php55to56
By Greg Reedy, PHP/MySQL Developer at InteractOne

What you need to know about upgrading PHP v5.5 to v5.6

If you’re a Magento merchant or developer, you’re well aware that the platform is well into its new life as Magento 2, however, you may not be aware that it is also well underway into a new life of patches and upgrades. Magento 2.0 was released in Q4 2015, and now – at the time of this writing – has iterated from version 2.0.0 all the way up to 2.1.1. That’s eleven minor version upgrades!  Now, is that something new or abnormal? Nope. This happens all the time with software, but sometimes updates occur within these minor upgrades that can affect things immensely, so it’s important to keep on top of what has changed and how it could affect your Magento store’s online environment.

Magento is, of course, built on PHP, and in an effort to stay up-to-date with technology, the requirements to run Magento have updated as well.

In the initial minimum requirements published with the M2 release, PHP versions 5.5.22 to 7.1.0 were acceptable.

from the original Magento 2 Developer Documentation

PHP

5.6.x
5.5.x, where x is 22 or greater
7.0.2 up to 7.1.0, except for 7.0.5
However, upon the release of Magento 2.1, support for PHP 5.5 ended.

from updated M2 Developer Documentation

System requirements

Our technology stack is built on PHP and MySQL. Magento 2.1.0 supports:

PHP 5.6 We do not support PHP 5.5x
PHP 7.0.2, 7.0.6 up to 7.1
MySQL 5.6
Apache 2.2 or 2.4
nginx 1.8(or latest mainline version)

Why does this matter?

It matters because your hosting company is likely about to automatically upgrade PHP on all of their servers to 5.6 from 5.5, and your M1 installation may not be ready for it! One day you wake up, your site is down, and clearing those Magento caches has zero effect.

All you see is something like this in the error log:

ERR (3): Deprecated functionality: iconv_set_encoding(): Use of iconv.internal_encoding is deprecated  in lib/Zend/Locale/Format.php on line 311

Why is this happening?

Because PHP 5.5 has come to an “end of life” (EOL) and nobody invited you to the funeral!2016-09-30_1142

So long PHP 5.5!

tombstone

How do I fix it?

To keep your sturdy M1 site humming right along, there are a few simple fixes to get it to play nicely with PHP 5.6:

Fix #1: Upgrade to the latest version!

Magento’s latest releases of M1 have made the backwards compatibility to handle the deprecated functions. You can simply upgrade to the latest versions of Community Edition (1.9.2.4) or Enterprise Edition (1.14.2.4) and the deprecated functionality shouldn’t be an issue.

Fix #2: Patch the offending files in the Zend

The main issues really fall in the Zend library that ships with M1. If upgrading isn’t immediately possible (let’s inject here that official upgrades and updates are always recommended), a mediary solution can be to simply patch the offending files in the Zend folder by copying them to your local codepool and modifying the necessary lines.

Copy from:

lib/Zend/Locale/Format.php
lib/Zend/Service/Audioscrobbler.php
lib/Zend/Service/Technorati.php
lib/Zend/Validate/Hostname.php
lib/Zend/Validate/StringLength.php
lib/Zend/XmlRpc/Client.php

Copy to:

app/code/local/Zend/Locale/Format.php
app/code/local/Zend/Service/Audioscrobbler.php
app/code/local/Zend/Service/Technorati.php
app/code/local/Zend/Validate/Hostname.php
app/code/local/Zend/Validate/StringLength.php
app/code/local/Zend/XmlRpc/Client.php

Edit the newly copied files by searching for “internal_encoding” and replacing it with “default_charset”. Be sure that the “internal_encoding” string is a parameter of an iconv related function, otherwise it will break the code. (EXAMPLE: Don’t replace any other parameters or variable names by accident, such as “mb_internal_encoding” or “$internal_encoding” or any other unrelated elements, or you may otherwise certainly break your code.

In the official releases of the latest versions, the files listed above have defined constants to compare the PHP version against and they set the encoding accordingly.

Example:

2016-09-30_1334

However, setting the encoding in the above listed files to a fixed value should be fine as long as the PHP version is 5.6 or above.

Example:

2016-09-30_1342

With the actively occurring PHP upgrades happening now among hosting companies across the internet, it’s imperative to make sure your online store is up-to-date and ready. Many hosting companies will upgrade their servers without warning which could cause major outages and downtime. It is often up to merchants to be pro-active and ensure their stores remain open for business in the event of an unanticipated update such as this (which is no longer in the distant future!).

Contact InteractOne today and have our Magento team review your site’s integrity and viability for growth!