Let’s install PHP 7.x on CentOS or Ubuntu Server

Let's install PHP 7.x on CentOS or Ubuntu Server
Let's install PHP 7.x on CentOS or Ubuntu Server

I wasn’t in a hurry to install PHP 7.x. Because a lot of themes and plugins didn’t work good with PHP 7.x or totally didn’t support it. But today I think the time has come. I need to warn, I didn’t notice improvements in speed in admin section of WordPress. My public side in CDN cache, so I didn’t expect speed could be improved right after I installed PHP 7.x.

Anyway, let’s get back to the installation. If you have old PHP version, like 5.x, then we should delete it first.

Remove old PHP

In CentOS:
yum remove php-*

In Ubuntu Server:
sudo apt-get update
sudo apt-get purge php5-common -y

Install PHP 7.x in CentOS

To install in CentOS, first of all, we need add repository information corresponding.

CentOS/RHEL7.x:
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/RHEL6.x:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

And now finally we can install PHP 7.x and some of the most commonly used extensions.

If you need PHP 7.0:
yum install php70w php70w-opcache php70w-cli php70w-curl php70w-common php70w-gd php70w-mbstring php70w-bcmath php70w-mcrypt php70w-mysqlnd php70w-mysqli php70w-xml

If you need PHP 7.1:
yum install php71w php71w-opcache php71w-cli php71w-curl php71w-common php71w-gd php71w-mbstring php71w-bcmath php71w-mcrypt php71w-mysqlnd php71w-mysqli php71w-xml

Restart Apache:
service httpd restart

Install PHP 7.x in Ubuntu Server

If you didn’t have PHP before, then:
sudo apt-add-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.0

Or php7.1 if you need.

If you have old PHP version:
sudo apt-get update
sudo apt-get purge php5-common -y
sudo apt-get install php7.0 php7.0-opcache php7.0-cli php7.0-curl php7.0-common php7.0-gd php7.0-mbstring php7.0-bcmath php7.0-mcrypt php7.0-mysql php7.0-mysqlnd php7.0-mysqli php7.0-xml -y

Or change to php7.1 if you need.
sudo apt-get --purge autoremove -y

Restart Apache:
sudo /etc/init.d/apache2 restart

Something else

You don’t need install Alternative PHP Cache for PHP 7.x, because you’ll use OPcache.