skip to Main Content

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


  1. Use update-alternatives to set the default php version:

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

    If you get an error no alternatives for php, refer to my answer on U&L to add php to update-alternatives ( replace python by php).

    Login or Signup to reply.
  2. 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:

    sudo systemctl stop php8.0-fpm
    sudo systemctl disable php8.0-fpm
    
    sudo apt install php7.4-fpm
    sudo systemctl start php7.4-fpm
    sudo systemctl enable php7.4-fpm
    
    sudo a2disconf php8.0-fpm
    
    Login or Signup to reply.
  3. Thank you, that worked for me too. I used it to enable 7.4 and disable 8.1 which had the same issue:

    sudo a2dismod php5.6
    sudo a2dismod php8.1
    sudo a2enmod php7.4
    sudo systemctl start php7.4-fpm
    sudo systemctl enable php7.4-fpm
    sudo a2disconf php8.1-fpm
    sudo service apache2 restart
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search