Skip to main content

Change PHP Version

If you've ever wondered how to change you're PHP version on Linux servers, then this guide is for you.  Besides having the correct packages installed you also have to use commands to change the default version that's used.  

 

For Apache (Debian/Ubuntu)

To change the default PHP version for an Apache web server you need to disable the current Apache PHP Module and enable the new Apache PHP Module.  

a2dismod php7.3
a2enmod php7.4
systemctl restart apache2

 

For PHP CLI (Debian/Ubuntu)

The CLI version of PHP is often used to run PHP commands in a web site directory.  When you run the php -v command, it's returning the CLI version of PHP and not the one Apache is using.  To update this version, you have to run the following command.  As long as you have the version of PHP you want to use installed you don't have to worry about the path, just change the number at the end to version you want to use. 

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