Site Issues after upgrading PHP
After upgrading to PHP 7, you may notice that your site is having issues. For example on a WordPress site, certain plugins will be disabled and you will see messages stating that certain PHP modules are missing.
eg.
- requires the function mb_detect_encoding to import and export CSV files
- …currently has no PHP cURL library activated
- AWS plugin is disabled
- mb_detect_encoding not enabled
- SOAP module not enabled
- ZipArchive Library is missing or disabled
- PHP Fatal error: Cannot redeclare class wfWAFWordPressRequest
The admin.php?page=wc-status page will tell you that certain PHP modules are missing as well.
After installing these modules on your server and confirming that they are working, your site may still produce these errors.
From the command line, the following command will output what version of PHP is being used.
php -i | grep -i 'PHP Version' PHP Version => 7.1.8-2+ubuntu14.04.1+deb.sury.org+4 PHP Version => 7.1.8-2+ubuntu14.04.1+deb.sury.org+4
And this will tell you what php.ini file is being looked at:
php -i | grep -i 'php.ini' Configuration File (php.ini) Path => /etc/php/7.1/cli Loaded Configuration File => /etc/php/7.1/cli/php.ini
But, this can fool you! It shows you the php.ini file that is used by the PHP CLI, NOT the Apache web server serving your site!
How to see what version of PHP Apache is using
Is Apache still using the old php.ini file?
To see, output the php.ini file as Apache “sees” it by creating a file with in the root of your website and checking what version is being used.
WARNING: Give this file an obscure name. Do not name it phpinf.php. We do not want to give malicious coders any information about our system, do we?
REMOVE THIS FILE as soon as you are done with it as it is a security risk to have it there.
For this article, I am using an example of replacing PHP 5.6 with PHP 7.1 on an Ubuntu 14 server.
If you have installed PHP 7.1
sudo apt-get -y install php7.1
If Apache is still looking at PHP5 (or whatever older version you had), it is likely that the Apache module for the upgraded PHP version is not installed.
One way to check for this is to take a look at the list of Apache modules.
On the command line, one cal list the enabled modules filtered for php modules like this:
sudo ls -la /etc/apache2/mods-enabled/php* lrwxrwxrwx 1 root root 29 Aug 30 07:37 /etc/apache2/mods-enabled/php5.6.conf -> ../mods-available/php5.6.conf lrwxrwxrwx 1 root root 29 Aug 30 07:37 /etc/apache2/mods-enabled/php5.6.load -> ../mods-available/php5.6.load
If your output lists your old PHP version, then Apache needs the new PHP module installed and enabled.
Tell Apache to use the right PHP Version
You will first need to disable the old PHP module. Then install the Apache module for the new PHP version. If you have not yet installed the new PHP version, this can be done all on one line like this:
Here are the commands:
# First disable the old PHP module sudo a2dismod php5.6 # Then install the apache module for the new php version sudo apt-get -y install libapache2-mod-php7.1 # If you have not yet installed the new PHP version, # this can be done all on one line like this: sudo apt-get -y install php7.1 libapache2-mod-php7.1 # IMPORTANT -- RESTART APACHE SERVER -- sudo service apache2 restart