aizu's Knowledge Base
    • Go to: aizu.my Homepage
    • Recent
    • Tags
    • Register
    • Login

    Multiple PHP 8.3 and 7.4 - Ubuntu 24

    Linux
    1
    1
    270
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      aizu
      last edited by aizu

      To run multiple PHP versions (8.3 and 7.4) on Ubuntu 24, you can install PHP 7.4 alongside PHP 8.3 and configure PHP-FPM to handle both versions. Here’s a step-by-step guide:

      Step 1: Add PHP 7.4 Repository
      First, you need to add the ondrej/php PPA, which allows you to install older PHP versions like 7.4.

      sudo apt update
      sudo apt install software-properties-common
      sudo add-apt-repository ppa:ondrej/php
      sudo apt update
      

      Step 2: Install PHP 7.4 and PHP 7.4-FPM
      Now, install PHP 7.4 along with its FPM package and any required extensions.

      sudo apt install php7.4 php7.4-fpm php7.4-cli php7.4-common php7.4-mysql php7.4-xml php7.4-mbstring php7.4-curl
      

      Step 3: Ensure PHP 8.3 FPM is Installed
      Make sure you also have PHP 8.3 FPM installed (if not already):

      sudo apt install php8.3-fpm
      

      Step 4: Configure Nginx to Use Different PHP-FPM Versions
      Now, you need to modify your Nginx configuration to point to the correct PHP-FPM socket for each site or location.

      For PHP 8.3 (default):
      In your Nginx config file (e.g., /etc/nginx/sites-available/default), set the fastcgi_pass directive to PHP 8.3:

      nginx
      Copy code
      location ~ .php$ {
      fastcgi_pass unix:/run/php/php8.3-fpm.sock;
      include fastcgi_params;
      }

      For PHP 7.4 (for specific locations or sites):
      For specific sites or locations where you want to use PHP 7.4, you can point to the PHP 7.4 FPM socket:

      location ~ \.php$ {
          fastcgi_pass unix:/run/php/php7.4-fpm.sock;
          include fastcgi_params;
      }
      

      Step 5: Enable and Restart PHP-FPM Services
      Enable both PHP-FPM services to ensure they start on boot:

      sudo systemctl enable php8.3-fpm
      sudo systemctl enable php7.4-fpm
      

      Then restart both services:

      sudo systemctl restart php8.3-fpm
      sudo systemctl restart php7.4-fpm
      

      Step 6: Set PHP 8.3 as the Default CLI Version (Optional)
      If you want to keep PHP 8.3 as the default for the CLI, use the update-alternatives command:

      sudo update-alternatives --set php /usr/bin/php8.3
      

      To switch to PHP 7.4 for the CLI:

      sudo update-alternatives --set php /usr/bin/php7.4
      

      Step 7: Verify Installation
      To check the installed versions of PHP-FPM, run:

      php -v          # To check the default CLI version
      sudo systemctl status php7.4-fpm
      sudo systemctl status php8.3-fpm
      

      Conclusion
      Now you have both PHP 8.3 and PHP 7.4 running on your Ubuntu 24 system, with PHP 8.3 as the default and the ability to use PHP 7.4 for specific locations or virtual hosts.

      1 Reply Last reply Reply Quote 0
      • First post
        Last post