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:

Step 2, Install PHP Versions and Extensions

Install both versions of PHP along with common Laravel dependencies:

Step 3: Prepare Laravel Project Directories

Create directories for each Laravel version:

Each project must point its Nginx root to the public/ directory:

Set correct permissions:

Step 4, Configure Nginx Server Blocks with PHP and SSL

Create two Nginx config files:

/etc/nginx/sites-available/laravel74.conf

/etc/nginx/sites-available/laravel82.conf

Enable both sites:

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:

Ensure writable directories:

Step 6: Local Testing with /etc/hosts

Add the following to /etc/hosts for testing on a local machine:

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.

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.