PHP 7 was released end of last year, and since it speeds up PHP execution so much, we can only recommend people to migrate their sites to PHP 7. With Magento 2, PHP 7 is supported out of the box. With Magento 1, this is more cumbersome. Let's summarize some of the aspects.

Patching Magento 1.9

First of all, if you are looking for running Magento 1 under PHP 7, make sure to run the latest Magento 1.9 first - at the time of writing 1.9.2.4. Unfortunately this version is not supporting PHP 7 out of the box, leading to a few PHP Fatal Errors and an inaccessible Magento Admin Panel if you try. This is easily fixed though. While there are various patches out there allowing you to make Magento PHP 7 compatible, we only recommend the package from Inchoo:

Install this extension and you should be ready to go: github.com/Inchoo/Inchoo_PHP7

Scanning your code base

While the Inchoo extension fixes the Magento core, there might be other issues in your shop. You could setup a testing site and see how it goes. Another way is by scanning your Magento codebase for common issues. A very valuable tool here is the tool php7cc: github.com/sstalle/php7cc

Personally I prefer to download the PHAR file php7cc.phar either from the GitHub releases page or via composer. Next I place the PHAR in my system folder so I can access it from anywhere:

mv php7cc.phar /usr/local/bin/php7cc
chmod 755 /usr/local/bin/php7cc

Once installed, you can use it to scan your Magento site as follows:

cd /path/to/magento
/usr/bin/php -d memory_limit=1G /usr/local/bin/php7cc \
    --extensions=php,phtml --except=app/code/core .

Here, we first switch to the Magento base folder. But instead of calling the php7cc binary directly, we call it via the php executable itself, which allows us to also specify a memory_limit. The arguments to php7cc include picking up on both PHP files and PHTML files, while excluding the Magento core.

The php7cc binary itself is PHP 7 compatible, so when you have both a PHP 5.X executable and a PHP 7 executable, you can call php7cc using PHP 7 which will work even faster. The php7cc wiki mentions also some issues with Xdebug. Because of performance, we recommend to keep xdebug disabled by default, and only enable it when you actually want to use it.

Encrypted extensions

In general, we believe that people should stay away from encrypted extensions (mostly ionCube) but with this PHP 7 story our urging becomes bigger: During some PHP 7 migrations we have found that some encrypted Magento extensions simply seem to check for a PHP version starting with 5.. We found proof for this because these ionCube extensions were running without issues when replacing the PHP version 7.0.2 with 5.7.0 (which we definitely do not recommend you should do). In short: Get away from encrypted extensions.

Other possible issues

The PHP site itself mentiones various incompatibilities (http://php.net/manual/en/migration70.incompatible.php. While the tool php7cc is great, it is not allknowing. For instance, one of the Magento 1.9 core issues with PHP 7 deals with the global variable $_SESSION which is not detected by php7cc.

One of the more rigurous changes is that the mysql extension is gone in PHP 7. This means that any call to a function like mysql_query() will not work anymore. While the mysqli extension with functions like mysqli_query() does work, code within Magento should be using the PDO adapters of Magento instead. Likewise the ereg extension is removed, but I'm not sure if anyone noticed - ereg functions are already outdated for over 10 years.

Summary

Thanks to the Inchoo_PHP7 extension, migrating to PHP 7 becomes easy. We have migrated about half a dozen shops already to PHP 7, with only the requirement of installing this extension. So that's great. But you can't know for sure. To know for sure whether your shop works under PHP 7, we recommend you to setup a testing site, and if possible scan the code for possible issues. Hope you found this useful.

Posted on March 17, 2016

About the author

Author Jisse Reitsma

Jisse Reitsma is the founder of Yireo, extension developer, developer trainer and 3x Magento Master. His passion is for technology and open source. And he loves talking as well.

Sponsor Yireo

Looking for a training in-house?

Let's get to it!

We don't write too commercial stuff, we focus on the technology (which we love) and we regularly come up with innovative solutions. Via our newsletter, you can keep yourself up to date on all of this coolness. Subscribing only takes seconds.

Do not miss out on what we say

This will be the most interesting spam you have ever read

We don't write too commercial stuff, we focus on the technology (which we love) and we regularly come up with innovative solutions. Via our newsletter, you can keep yourself up to date on all of this coolness. Subscribing only takes seconds.