Make PHP7 and PHP 8 live together
I've upgraded from PHP 7 to PHP 8. As it's usually the case with PHP, I still have php7.4 in /usr/bin
(alongside with php8.0). But, when I run the php -v
command, it answers php8.0.
Since then, when trying to install software (for example Docker and VirtualBox), I get the error message php7.4-fpm.service: Failed with result 'exit-code'
, followed by Failed to start The PHP 7.4 FastCGI Process Manager
. It seems therefore that I need php7.4 to run to install such applications.
But I use PHP 8 functionalities to code a website and therefore don't want to get back to php7.4
Is there a way to use php8.0 and php7.4 at the same time? I could make PHP 8 work on a virtual machine but it's quite heavy.
I'm on Ubuntu 20 (but I'm not sure that this problem is OS-specific).
Zlotz
My Answer:
Yes, it is possible to have both PHP 7.4 and PHP 8.0 installed and running on the same system. You can achieve this by using PHP-FPM (FastCGI Process Manager) to manage multiple PHP versions.
Here's a general outline of how you can set this up on Ubuntu 20:
1. Install PHP 7.4-FPM and PHP 8.0-FPM:
sudo apt install php7.4-fpm php8.0-fpm
2. Configure PHP 7.4-FPM and PHP 8.0-FPM to run on different ports. You can do this by editing the respective pool configuration files located in `/etc/php/7.4/fpm/pool.d/` and `/etc/php/8.0/fpm/pool.d/`.
3. Restart the PHP-FPM services for both versions:
sudo systemctl restart php7.4-fpm
sudo systemctl restart php8.0-fpm
4. Update your web server configuration (e.g., Nginx or Apache) to use the appropriate PHP-FPM version for each website or application.
5. You can now switch between PHP 7.4 and PHP 8.0 by configuring your web server to use the desired PHP-FPM version for each site.
By following these steps, you should be able to have both PHP 7.4 and PHP 8.0 running simultaneously on your Ubuntu 20 system. This way, you can continue using PHP 8.0 for your website development while still being able to run applications that require PHP 7.4.
Rate this post
3 of 5 based on 6041 votesComments