I need to switch the PHP version from 8.0 to 7.4 on Ubutnu 20.04. I tried to run the commands below (but without success):
sudo a2dismod php8.0
sudo a2enmod php7.4
sudo service apache2 restart
When I open a local webpage with the PHP info <?php phpinfo(); ?>
, the PHP version is still 8.0.3 and not 7.4.
Note that when I execute the command sudo a2enmod php7.4
I get the following output:
dan@dan:~$ sudo a2enmod php7.4
Considering dependency mpm_prefork for php7.4:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Enabling module mpm_prefork.
Considering conflict php5 for php7.4:
Enabling module php7.4.
To activate the new configuration, you need to run:
systemctl restart apache2
Maybe is that the source of the issue?
3
Answers
Use
update-alternatives
to set the defaultphp
version:If you get an error
no alternatives for php
, refer to my answer on U&L to addphp
toupdate-alternatives
( replacepython
byphp
).I have found the answer. The problem was that apache was still trying to use php-fpm-8.0 and in order to solve the problem I simply installed the php7.4-fpm and disabled the php8.0-fpm with the following commands:
Thank you, that worked for me too. I used it to enable 7.4 and disable 8.1 which had the same issue: