Switch PHP version in Ubuntu & Apache
- Bilal Malik
- Apr 25, 2021
- 1 min read
For example, if you are using the PHP 7.2 version and you are looking to switch the version to PHP 7.4.
We need to update the PHP version in two places.
CLI
Apache
1. Switch PHP version in CLI
Before that check your PHP current version in the terminal by using the below command.
php -v
Then run the below command to switch the PHP CLI version.
sudo update-alternatives --set php /usr/bin/php7.4
Then again check your PHP version to make sure it was updated.
php -v
2. Switch PHP version in Apache webserver
Before that check the apache using PHP version by phpinfo(). Then disable the apache using the php version. As per the example, apache using 7.2 so we are going to disable PHP 7.2 in apache.
sudo a2dismod php7.2
Then enable the needed version, as per the example, we are going to enable 7.4
sudo a2enmod php7.4
Finally, restart the apache webserver.
sudo service apache2 restart
Please check the phpinfo() to make sure the PHP version updated in apache.
I hope it helps. Thanks.
Comments