If you’re hosting Laravel apps on Debian 12, you may face the need to support multiple PHP versions — for example, running a legacy Laravel project that requires PHP 7.4 alongside a new project using PHP 8.2. Since Debian 12 ships only with PHP 8.2 by default, this guide will walk you through installing PHP 7.4, configuring Nginx to run both Laravel projects, and securing them with Cloudflare SSL.
Step 1, Add Sury PHP Repository
Install Sury’s repository to access PHP 7.4 packages:
0 1 2 3 4 5 6 |
sudo apt update sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2 wget -qO - https://packages.sury.org/php/apt.gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/php.gpg echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list sudo apt update |
Step 2, Install PHP Versions and Extensions
Install both versions of PHP along with common Laravel dependencies:
0 1 2 3 4 5 6 |
# PHP 7.4 sudo apt install -y php7.4 php7.4-fpm php7.4-mysql php7.4-mbstring php7.4-xml php7.4-curl php7.4-zip # PHP 8.2 sudo apt install -y php8.2 php8.2-fpm php8.2-mysql php8.2-mbstring php8.2-xml php8.2-curl php8.2-zip |
Step 3: Prepare Laravel Project Directories
Create directories for each Laravel version:
0 1 2 |
sudo mkdir -p /var/www/laravel74 /var/www/laravel82 |
Each project must point its Nginx root to the public/
directory:
0 1 2 3 |
cd /var/www/laravel74 && composer create-project laravel/laravel:^8 . cd /var/www/laravel82 && composer create-project laravel/laravel:^10 . |
Set correct permissions:
0 1 2 |
sudo chown -R www-data:www-data /var/www/laravel74 /var/www/laravel82 |
Step 4, Configure Nginx Server Blocks with PHP and SSL
Create two Nginx config files:
/etc/nginx/sites-available/laravel74.conf
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
server { listen 80; server_name laravel74.example.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name laravel74.example.com; ssl_certificate /etc/ssl/certs/cloudflare.pem; ssl_certificate_key /etc/ssl/private/cloudflare.key; include snippets/ssl-params.conf; root /var/www/laravel74/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:/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } } |
/etc/nginx/sites-available/laravel82.conf
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
server { listen 80; server_name laravel82.example.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name laravel82.example.com; ssl_certificate /etc/ssl/certs/cloudflare.pem; ssl_certificate_key /etc/ssl/private/cloudflare.key; include snippets/ssl-params.conf; root /var/www/laravel82/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:/run/php/php8.2-fpm.sock; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } } |
Enable both sites:
0 1 2 3 4 |
sudo ln -s /etc/nginx/sites-available/laravel74.conf /etc/nginx/sites-enabled/ sudo ln -s /etc/nginx/sites-available/laravel82.conf /etc/nginx/sites-enabled/ sudo nginx -t && sudo systemctl reload nginx |
Make sure to place Cloudflare’s origin SSL certs in the specified paths or use Let’s Encrypt as an alternative.
Step 5: Final Laravel Setup
Run the artisan setup using the proper PHP version:
0 1 2 3 |
cd /var/www/laravel74 && php7.4 artisan config:cache cd /var/www/laravel82 && php8.2 artisan config:cache |
Ensure writable directories:
0 1 2 |
sudo chown -R www-data:www-data storage bootstrap/cache |
Step 6: Local Testing with /etc/hosts
Add the following to /etc/hosts
for testing on a local machine:
0 1 2 3 |
127.0.0.1 laravel74.example.com 127.0.0.1 laravel82.example.com |
Conclusion
You’ve now set up a robust multi-version Laravel environment on Debian 12 with Nginx, secured with Cloudflare SSL. This setup allows you to run legacy and modern Laravel apps in parallel with clean separation and flexibility.