You have undoubtedly noticed, PHP7 is installed by default on Ubuntu 16.04 LTS.
This can be problematic if you have an old WordPress project that uses the php mysql extension, which is no longer available under php7.
The solution is to install an apache 2 configuration for both php 5.6 and php 7, and to enable one or the other as needed.
We start by installing PHP 5.6
sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0 php5.6-xml
To switch from php 5.6 to php 7
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart sudo ln -sfn /usr/bin/php7.0 /etc/alternatives/php
To switch from php7 to php 5.6:
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart sudo ln -sfn /usr/bin/php5.6 /etc/alternatives/php
We can then automate the switching from one to the other with an alias in our bashrc:
vi ~/.bashrc alias setphp7='sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart; sudo ln -sfn /usr/bin/php7.0 /etc/alternatives/php' alias setphp5='sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart; sudo ln -sfn /usr/bin/php5.6 /etc/alternatives/php'
Compatibility context
This procedure documents a PHP or Apache environment from its time. PHP 5.x and 7.x branches no longer receive standard support from the PHP project: do not deploy this configuration as is on a new server.
- First identify the versions actually installed and the loaded modules.
- Prepare a configuration backup and a rollback procedure.
- Validate the syntax, then the critical paths, on a version of PHP that is still maintained.
Reference: currently supported PHP versions.