PHP 7

Install PHP 7 on CentOS 7 and 6


This guide will help you install or upgrade PHP 7 on your webserver. It involves adding fedora epel repositories so that you can use “yum” to install packages and updates. Keep in mind when upgrading that there were a lot of major changes in PHP version 7 and some of your web applications may not be compatible. On php.net there is a good article describing Backward incompatible changes. That being said if you are still interested in upgrading, many have said that version 7 can be as much or more than twice as fast as previous versions.

This guide is based off of Webtatic’s guide here, and uses their repositories.

Installing the Repositories

First you need to install the EPEL (Extra Packages for Enterprise Linux) repository and then the Webtatic  repository, use the set of commands appropriate for your version of CentOS:

CentOS 7

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

CentOS 6

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

Installing PHP 7

Now you can install PHP version 7 using yum:

yum install php70w php70w-opcache

It will prompt you to install the GPG key the first time you try to use the repos, answer “y” and it will install PHP 7.

ViMbAdmin

If you were directed here by my mailserver configuration series as part of the ViMbAdmin install, you are also going to need the pgsql plugin for php and mod_ssl:

yum install php70w-pgsql mod_ssl

I haven’t yet tested ViMbAdmin with PHP 7, I will update this post if there are any other requirements.

Common Problems

When upgrading to PHP 7 you could encounter some problems.

php-common failed

On my webserver I previously had PHP 5 installed. When I went to install PHP 7, the installation failed because of conflicting php-common packages. I resolved this problem by removing the old version and running the install command above again.

yum remove php-common
yum install php70w php70w-opcache

Webtatic’s guide says you can upgrade php-common by installing and using “yum-plugin-replace”. I have not tested this method because I didn’t read that far down their post before simply removing and reinstalling the problem package. Here are the commands Webtatic gives:

yum install yum-plugin-replace
yum replace php-common --replace-with=php70w-common

Either method should work, I think the first method is a bit cleaner though because it doesn’t involve installing additional packages. If you are installing PHP 7 on a CentOS minimal server for the first time, you probably wont run into this issue.


You must be logged into post a comment.