Running Drupal on a proper PHP version with IUS

I recently read Thijs Feryn post on the maturity of PHP and he makes a convincing argument for actually using what PHP provides with 5.5 now being stable.

Drupal 7 has seen many improvements over the past year in regards to 5.4 compatibility and as it turns out, it now runs pretty smoothly, though many modules still create E_NOTICEs due to legacy code. The breakage which 5.4 caused in many places when Drupal 7 (and let’s not even talk about a 6 site) came out is not comparable with upgrading from 5.4 to 5.5, which is mostly harmless.

Managing PHP versions

You have basically two options for upgrading PHP on your server: find some pre-compiled packages or build from source. The latter should be avoided by nearly everyone, unless you’re willing to diligently subscribe to a release mailing list and compile again and again.

On CentOS/RHEL, which is my preferred hosting platform at the moment one can rely on the excellent IUS repository. It makes switching between 5.3, 5.4 and 5.5 extremely easy. Once you have IUS installed, you can select your packages via the name php5Xu. Which means you can switch between 5.3 and 5.5 simply by removing the packages installed from php53u and installing again with php55u. All I needed afterwards to get PHP running again was copying the /etc/php-fpm.d/www. conf.rpmsave over www. conf and so 15 minutes later this blog is running on 5.5:

# yum list installed | grep php
php55u-cli.x86_64 5.5.5-2.ius.centos6 @ius
php55u-common.x86_64 5.5.5-2.ius.centos6 @ius
php55u-fpm.x86_64 5.5.5-2.ius.centos6 @ius
php55u-gd.x86_64 5.5.5-2.ius.centos6 @ius

An additional benefit is that IUS provides packages in sync with the latest released package. This is very helpful in determining what you are actually running. For example, your server might report that you are running 5.3.3 (as stock CentOS 6.4 does), even if critical fixes have been backported by RedHat, Fedora, et al from later versions, with IUS you’ll get a proper 5.3.27.

Caveat: Of course, don’t try this on production if you don’t know what you’re doing.