How to Install and Configure a PHP Framework (Laravel, Symfony) on Debian 12 Bookworm

This guide will walk you through installing and configuring both Laravel and Symfony on a Debian 12 system.

Developing modern web applications often calls for robust and scalable frameworks. PHP frameworks like Laravel and Symfony are popular choices among developers for their efficiency, comprehensive features, and strong community support. If you’re running Debian 12 Bookworm, you have a stable and reliable base for web development. This guide will walk you through installing and configuring both Laravel and Symfony on a Debian 12 system.

Whether you’re building REST APIs, full-stack apps, or enterprise-level systems, having a solid local development setup is essential. Let’s break down the steps.


System Requirements

For Laravel and Symfony on Debian 12, you’ll need:

  • Debian 12 Bookworm
  • PHP 8.1+
  • Composer
  • Web Server (Apache or Nginx)
  • Database (MySQL/MariaDB or PostgreSQL)
  • Curl, Git, and other development tools

Step 1: Update and Upgrade Your System

First, update your system packages to ensure you’re starting with the latest software versions.

sudo apt update && sudo apt upgrade -y

Install basic dependencies:

sudo apt install curl git unzip zip software-properties-common -y

Step 2: Install Apache/Nginx, PHP, and Required Extensions

Choose your web server

You can install either Apache or Nginx. Laravel and Symfony support both.

Install Apache:

sudo apt install apache2 libapache2-mod-php -y

Or install Nginx:

sudo apt install nginx -y

Install PHP and Extensions

Laravel and Symfony require PHP 8.1 or higher. Debian 12 includes PHP 8.2 by default.

sudo apt install php php-cli php-common php-mbstring php-xml php-bcmath php-curl php-zip php-mysql php-pgsql php-intl php-gd php-soap -y

You can verify PHP installation with:

php -v

Expected output should be something like:

PHP 8.2.x (cli) (built: ...)

Step 3: Install Composer

Composer is the dependency manager for PHP. It’s required for both Laravel and Symfony installations.

cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Verify the installation:

composer

You should see Composer’s help screen if it’s installed correctly.


Step 4: Setting Up Laravel

Create a new Laravel project

cd /var/www/
sudo composer create-project laravel/laravel laravelapp

Set the correct permissions:

sudo chown -R www-data:www-data /var/www/laravelapp
sudo chmod -R 755 /var/www/laravelapp

Configure Apache (optional step if you’re using Apache)

Create a virtual host file:

sudo nano /etc/apache2/sites-available/laravelapp.conf

Add the following:

<VirtualHost *:80>
    ServerName laravel.local
    DocumentRoot /var/www/laravelapp/public

    <Directory /var/www/laravelapp/public>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/laravel_error.log
    CustomLog ${APACHE_LOG_DIR}/laravel_access.log combined
</VirtualHost>

Enable the site and the mod_rewrite module:

sudo a2ensite laravelapp.conf
sudo a2enmod rewrite
sudo systemctl reload apache2

Update your /etc/hosts file:

sudo nano /etc/hosts

Add:

127.0.0.1 laravel.local

Step 5: Setting Up Symfony

Install Symfony CLI

wget https://get.symfony.com/cli/installer -O - | bash
sudo mv ~/.symfony*/bin/symfony /usr/local/bin/symfony

Verify the installation:

symfony -v

Create a Symfony project

Navigate to your web root and create the project:

cd /var/www/
sudo symfony new symfonyapp --webapp

Set permissions:

sudo chown -R www-data:www-data /var/www/symfonyapp
sudo chmod -R 755 /var/www/symfonyapp

Configure Apache

Create a virtual host file:

sudo nano /etc/apache2/sites-available/symfonyapp.conf

Add the following:

<VirtualHost *:80>
    ServerName symfony.local
    DocumentRoot /var/www/symfonyapp/public

    <Directory /var/www/symfonyapp/public>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/symfony_error.log
    CustomLog ${APACHE_LOG_DIR}/symfony_access.log combined
</VirtualHost>

Enable the site:

sudo a2ensite symfonyapp.conf
sudo systemctl reload apache2

Update /etc/hosts:

127.0.0.1 symfony.local

Step 6: Configuring Virtual Hosts (Nginx Alternative)

If you’re using Nginx, here’s how to configure Laravel and Symfony:

Laravel Nginx Block

server {
    listen 80;
    server_name laravel.local;
    root /var/www/laravelapp/public;

    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Symfony Nginx Block

server {
    listen 80;
    server_name symfony.local;
    root /var/www/symfonyapp/public;

    index index.php;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Test and reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

Step 7: Testing Your Setup

Now you can test your frameworks:

  • Visit http://laravel.local and you should see the Laravel welcome page.
  • Visit http://symfony.local and you should see the Symfony welcome page.

Security & Best Practices

  • Use .env files to manage environment-specific configurations securely.
  • Disable debug mode in production (APP_DEBUG=false for Laravel).
  • Set correct file permissions for your projects (never give write access to the entire directory).
  • Install SSL certificates for production (Let’s Encrypt is a great option).
  • Keep your Composer dependencies updated.
  • Regularly back up your application and database.

Conclusion

Installing Laravel and Symfony on Debian 12 Bookworm is a straightforward process, provided you have Composer, PHP, and a web server properly configured. This setup enables you to develop and test PHP applications in a local environment that closely mirrors production servers.

Laravel offers a more opinionated framework with built-in features for rapid development, while Symfony gives you more flexibility and control. Regardless of your choice, both frameworks are mature, widely adopted, and a great fit for PHP developers.