This is one of the most common scenarios which arise when working with multiple projects on the same development server. For instance one of your project is in Drupal 8 running on PHP 7.4 while you are also running a Drupal10 site which requires PHP 8.1. Now how can you manage and enable different PHP versions for each projects. It might feel complex but its a straight forward process :
-
Find all the available PHP versions on the server
-
sudo update-alternatives --list php
OR -
cd /etc/php and ls -al
-
-
Nginx
- Update the nginx configuration of the site and its respective PHP version configuration at :
- Go To
cd /etc/nginx/sites-available/[site-name]
- Update PHP version in the above file
location ~ .php${ fastcgi_pass unix:/run/php/php-8.1-fpm.sock ...... } OR
location ~ .php${ fastcgi_pass unix:/run/php/php-7.4-fpm.sock ...... }
- Go To
- Now, restart the nginx server
sudo service nginx restart
- Update the nginx configuration of the site and its respective PHP version configuration at :
-
Navigate back to the project root directory, now if you are running composer you will need the required version available on the command line
sudo update-alternatives --set php /usr/bin/php8.1 OR
sudo update-alternatives --set php /usr/bin/php7.4
-
Now you can move back to your project run composer and validate your PHP version in your application.
-
Done.
Published on