How to change the default PHP version?

If you have multiple PHP versions installed on your Ubuntu server, you can change what version is the default one.

To set PHP 7.0 as the default, run:

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

To set PHP 7.2 as the default, run:

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

To set PHP 7.3 as the default, run:

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

If you’re following our LAMP tutorials and you’re using Apache, you can configure Apache to use PHP 7.2 with the following command:

sudo a2enmod php7.2

And then restart Apache for the changes to take effect:

sudo systemctl restart apache2