Update Centos to PHP7 via Remi repos

Published on 18.12.2015, by lubosdz

Update Centos to PHP7 via Remi repos

On 03.12.2015 has been released PHP7 with great performance & feature improvements.

Since I have a couple of applications running on PHP 5.5 branch with quite complicate environment settings I was wondering whether there is an easy way to simply upgrade to PHP7 without the need to do too much of manual uninstall/install stuff. I was actually surprised how easy things went on. So here is in short steps to upgrade existing PHP installation on Centos (applicable probably also to Fedora and Red Hat).

Following is assumed (or at least applied to my setup):

Steps to upgrade to PHP 7

First let's check installed PHP packages from remi PHP5 repository (just informative check):

yum list installed | grep remi

Remove all existing PHP packages:

yum remove php-*

Now php-fpm service is fully removed including dependencies, so there should be no conflicts with new branch. Now let's install PHP 7.0. We will use remi repository again via option --enablerepo=remi,remi-php70. Following is a single line:

yum --enablerepo=remi,remi-php70 install php-fpm php-common php-cli php-pear php-pdo php-mysqlnd php-gd php-mbstring php-mcrypt php-xml php-iconv php-soap php-opcache php-imagick php-tidy php-json php-openssl php-bcmath

Now I found that ZIP extension is in PECL repo only:

yum --enablerepo=remi,remi-php70 info php-*zip*

So I installed it from PECL:

yum --enablerepo=remi,remi-php70 install php-pecl-zip

THAT'S IT. Now PHP7 is installed, let's do some after work:

Start the service ..

service restart php-fpm

.. and check it - you should see PHP 7.0.X version via command line CLI:

php -v

.. or check where it is installed:

whereis php

Since php-fpm is newly installed service, ensure autostart:

chkconfig --levels 235 php-fpm on

Check in nginx configuration, e.g. update path to unix socket in nginx/conf.d/default.conf or in any of your virtual host file(s):

fastcgi_pass unix:/tmp/php7-fpm.sock;

Now navigating to webserver root URL (e.g. http://localhost) should display some HTML page but .... whooops, something went wrong and I see "502 Bad Gateway" error. This is pretty common access error meaning that nginx and php-fpm run under different owners and/or groups and therefore cannot talk to each other (via unix socket). Fix it:

  • in file /etc/nginx/nginx.conf add first line:

    user nginx;

  • in file /etc/php-fpm.d/www.conf comment out line:

    ; listen = 127.0.0.1:9000

and add lines:

listen = /tmp/php7-fpm.sock
listen.owner = nginx
listen.group = nginx

So now both services nginx and php-fpm will run under owner nginx so they both can access socket file in /tmp/php7-fpm.sock and the 502 Bad Gateway error should disappear.

Conclusion

Upgrading from PHP 5.4 or PHP 5.5 to PHP 7.0 branch is surprisingly easy. Remi Collet, the maintainer of the RPM repositaries does awesome job - many thanx for it. The repos are almost instantly updated with each new PHP release, e.g. PHP 7.0.1 officially released just 1 day ago as of writing this article already had the 7.0.1 version in repository. Moving to PHP7, the most secure, performant and feature-richest PHP branch should be a breeze - go for it!


Leave your comment..
Email will be converted into something like [michael AT gmail DOT com]
Note: Offensive and unrelated comments will be deleted.
Please enter result from the picture above.