I was setting up a development environment for a client’s existing application, and made the mistake of setting up the site on PHP7. Guess what? The site stopped functioning. Because the introduction of PHP7 has meant the deprecation of many PHP functions – the specific ones that I fell foul over are the MySQL functions (like mysql_connect()).
So in the interest of expediency, I was forced to drop back to PHP5.6. Which is annoying because I like to keep sites on the latest version.
In order to exploit the benefits of PHP7, I have to remediate the entire application… OR… use a custom PHP library to ‘mimic’ the old functions (and slow the frikkin’ site down…)
Has this happened to you yet?
Where you might find this problem
If you’re a WordPress user, then upgrading your PHP version might cause you grief. Some of your beloved plugins and themes that use the deprecated functions and features will stop working. Thing is, the problems won’t always be immediately obvious, especially if your site uses AJAX calls back into the server.
Forced Upgrades of Older PHP Versions
If you’re currently on an ancient version of PHP (and I mean version 4 and below) then your hosting company may force you to upgrade. Go check! You can usually find which version you’re currently on through your host’s control panel (like cPanel). Or, you can use phpinfo() from the command line on the box. Hosts will force upgrades if they deem older versions are a vulnerability – especially on shared hosts or virtual private servers (VPSs.)
Some hosts give you an automatic upgrade option. If left enabled, your PHP version will be upgraded unattended, leaving you with a potential mess. I always uncheck this option.
So my advice is…
Upgrade your PHP to version 7 with caution. Once you have done so, check everything. Here are some handy tips:
- Do a complete audit on your site after upgrading to make sure everything works. Test and test again. The last thing you want is a customer or user to find the problems for you. Especially on an e-commerce website (think of the lost revenue…)
- Search your site code for instances of the deprecated functions and functions in PHP7. I use Sublime Text‘s Find In Files feature which works a treat.
- Make no changes to your site until you have checked everything. The last thing you want is to put yourself between ‘a rock and a hard place’ by introducing change that requires PHP7, and then finding pain from deprecated functions.
- Un-check automatic PHP upgrade options on your host’s control panel. You should be in control of this process. But don’t leave yourself exposed to vulnerabilities by staying on old versions forever. This will create a different set of problems for you.
- If you really must, try this library (but be warned there may be a performance impact.)
- If you’re a WordPress user, keep your core, themes and plugins upgraded to the highest compatible level.
- The best outcome is to fix the issues – forward compatibility gives you piece of mind if any vulnerabilities are discovered and you have to upgrade.