I’m trying to switch php versions, get following response. I tried dismounting mpm_prefork and mpm_worker still no joy, any ideas please.
on Ubuntu 16.04
sudo a2enmod php5.6
Considering dependency mpm_prefork for php5.6:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Enabling module mpm_prefork.
Considering conflict php5 for php5.6:
Enabling module php5.6.
To activate the new configuration, you need to run:
service apache2 restart
Your commands looks correct. Did you restart apache before testing?
sudo service apache2 restart
The PHP module php5.6 made by Ondřej Surý can only be enabled by:
sudo a2dismod php7.0
sudo a2dismod php7.1
sudo a2dismod php7.2
sudo a2dismod php7.3
sudo a2dismod php7.4
sudo a2enmod php5.6
sudo update-alternatives --set php /usr/bin/php5.6
sudo service apache2 restart
I have found that this setup isn’t compatible with any other MPM modules other that PREFORK. You have to make sure you disable ALL other MPM modules first, before enabling the php5.6 mod.
If the mod won’t enable you might have to try to disable the other MPM’s.
sudo a2dismod mpm_prefork
sudo a2dismod mpm_worker
sudo a2dismod mpm_event
Then try to enable the mod again as it should auto enable the correct MPM.
$ sudo a2enmod php5.6
Considering dependency mpm_prefork for php5.6:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php5.6:
Enabling module php5.6.
To activate the new configuration, you need to run:
service apache2 restart
FYI, I like to put these commands into my ‘.bash_aliases’ so I always have them handy for DEV work.
# Aliases - PHP
alias php.info='php -i'
alias php5.6='sudo a2dismod php7.0 && sudo a2dismod php7.1 && sudo a2dismod php7.2 && sudo a2dismod php7.3 && sudo a2dismod php7.4 && sudo a2enmod php5.6 && sudo update-alternatives --set php /usr/bin/php5.6 && sudo service apache2 restart'
alias php7.0='sudo a2dismod php5.6 && sudo a2dismod php7.1 && sudo a2dismod php7.2 && sudo a2dismod php7.3 && sudo a2dismod php7.4 && sudo a2enmod php7.0 && sudo update-alternatives --set php /usr/bin/php7.0 && sudo service apache2 restart'
alias php7.1='sudo a2dismod php5.6 && sudo a2dismod php7.0 && sudo a2dismod php7.2 && sudo a2dismod php7.3 && sudo a2dismod php7.4 && sudo a2enmod php7.1 && sudo update-alternatives --set php /usr/bin/php7.1 && sudo service apache2 restart'
alias php7.2='sudo a2dismod php5.6 && sudo a2dismod php7.0 && sudo a2dismod php7.1 && sudo a2dismod php7.3 && sudo a2dismod php7.4 && sudo a2enmod php7.2 && sudo update-alternatives --set php /usr/bin/php7.2 && sudo service apache2 restart'
alias php7.3='sudo a2dismod php5.6 && sudo a2dismod php7.0 && sudo a2dismod php7.1 && sudo a2dismod php7.2 && sudo a2dismod php7.4 && sudo a2enmod php7.3 && sudo update-alternatives --set php /usr/bin/php7.3 && sudo service apache2 restart'
alias php7.4='sudo a2dismod php5.6 && sudo a2dismod php7.0 && sudo a2dismod php7.1 && sudo a2dismod php7.2 && sudo a2dismod php7.3 && sudo a2enmod php7.4 && sudo update-alternatives --set php /usr/bin/php7.4 && sudo service apache2 restart'
GIST: https://gist.github.com/djravine/376e81a018ba2b980750a5578deb3935
- @GAV It would be nice to have this accepted as the solution 😀 – Adan Rehtla Jun 4, 2019 at 3:59
php -v
(default PHP version)
From PHP 7.0 to PHP 5.6:
sudo a2dismod php7.0
sudo a2enmod php5.6
sudo update-alternatives --set php /usr/bin/php5.6
sudo service apache2 restart
From PHP 5.6 to PHP 7.0:
sudo a2dismod php5.6
sudo a2enmod php7.0
sudo update-alternatives --set php /usr/bin/php7.0
sudo service apache2 restart
To configure php7 to run with your server you need to do some configuration: 1. Make sure you remove any traces of php/php5 Open a terminal and:
cd /etc/apache2/mods-enabled
ls -la
The output should not contain any php5.conf or php5.load, but if it does, do the following:
# this is the proper way of disabling modules
sudo a2dismod php5
# run this only if the above command didn't remove the php5 sym-links
sudo rm php5.load
sudo rm php5.con
Now add the php7.0.conf and php7.0.load instead:
# this is the proper way of enabling modules
sudo a2enmod php7.0
# run this only if the above command didn't create the php7.0 sym-links
sudo ln -s php7.0.conf ../mods-available/php7.0.conf
sudo ln -s php7.0.load ../mods-available/php7.0.load
The output of ls -la php* should look like this:
lrwxrwxrwx 1 root root 29 Apr 15 03:55 php7.0.conf -> ../mods-available/php7.0.conf
lrwxrwxrwx 1 root root 29 Apr 15 03:55 php7.0.load -> ../mods-available/php7.0.load
After dealing with the modules we now come to the /etc/apache2/conf-enabled directory. Remove any traces of php/php5 here as well by sudo rm
Then, if needed do:
# the proper way of enabling configs
sudo a2enconf php7.0-cgi
sudo a2enconf php7.0-fpm
# do those commands only if the above didn't work out
sudo ln -s php7.0-cgi.conf ../conf-available/php7.0-cgi.conf
sudo ln -s php7.0-fpm.conf ../conf-available/php7.0-fpm.conf
The output of ls -la php* should look like this:
lrwxrwxrwx 1 root root 33 Apr 21 17:00 php7.0-cgi.conf -> ../conf-available/php7.0-cgi.conf
lrwxrwxrwx 1 root root 33 Apr 21 17:01 php7.0-fpm.conf -> ../conf-available/php7.0
And restart apache.
I have just resolved by following these steps.
How did you find this? I would have never gone this far! You are the champ! Thanks!
If sudo a2dismod php8.0
does not disable php8.0 module and you cannot switch php module to php7.4 then you can try following:
sudo a2disconf php8.0-fpm
sudo a2enmod php7.4
sudo systemctl reload apache2
Just try it
sudo a2dismod php7.2 && sudo update-alternatives --set php /usr/bin/php7.1 && sudo a2enmod php7.1 && sudo service apache2 restart
a2enmod
is a command related to apache2
while php -v
is a command which is related to php itself .
when you are running the following command
sudo a2enmod php5.6
you are then talking to apache2 not to php [ hey apache , enable php5 module for me instead of php7.0 ] so to speak .
to enable php5 in your server , you will have to :-
1) remove the current php version which is 7 , and then download your desired version of php .
or
2) download php 5 along side php 7
i think that php-version will be a great starting point to do some thing like that .
source : https://stackoverflow.com/questions/42506956/sudo-a2enmod-php5-6-php-v-still-shows-php-7-01-conflict