Cannot switch PHP version from 8.0 to 7.4

I'm trying to switch the PHP version from 8.0 to 7.4. I run the command below without success:

sudo a2dismod php8.0
sudo a2enmod php7.4
sudo service apache2 restart

Then 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?

1 Answer

Do you have PHP5 installed on the system?

You can list all loaded Apache modules with apache2ctl -M:

$ sudo apache2ctl -M
Loaded Modules: core_module (static) so_module (static) watchdog_module (static) http_module (static) log_config_module (static) logio_module (static) version_module (static) unixd_module (static) access_compat_module (shared) alias_module (shared) auth_basic_module (shared) authn_core_module (shared) authn_file_module (shared) authz_core_module (shared) authz_host_module (shared) authz_user_module (shared) autoindex_module (shared) deflate_module (shared) dir_module (shared) env_module (shared) filter_module (shared) headers_module (shared) mime_module (shared) mpm_prefork_module (shared) negotiation_module (shared) php7_module (shared) reqtimeout_module (shared) rewrite_module (shared) setenvif_module (shared) status_module (shared)

If you have multiple php versions, use a2dismod to disable the ones you do not need. From there, you can use update-alternatives to change the default version of PHP:

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

Note: Be sure to change php7.4 to the version you wish to use.

Once this is done, restart the web server:

sudo service apache2 restart

This should give you what you need.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like