Sunday, January 16, 2022

Ubuntu - Switch between multiple php versions on web and on command line

Multiple php versions are installed on ubuntu. You can find the config files of all the versions in /etc/php.

If you check the version on command line using

php --version

This version may be or may not be same as php version on browser (using apache2). You use phpinfo(); function to find the phpversion. You might have installed multiple php versions using apt-get install.

To shift different version on web using apache2

First disable the current enabled version using command

sudo a2dismod php7.0

then enable the other version which you want to use on web

sudo a2enmod php8.0

sudo service apache2 restart

To shift different version on terminal

sudo update-alternatives --set php /usr/bin/php8.0