How to install and upgrade PHP 7 for CentOS and Ubuntu

Cort Ammon

Member
Registered
Joined
Jul 8, 2016
Messages
48
Points
8
PHP 7 was officially launched, if you want to install PHP 7 to experience the speed of it, so I wrote this article guide you to upgrade to PHP 7 for CentOS and Ubuntu operating system and configuration for Apache web server and nginx.

Note that in PHP 7 has many functions have been removed so that if your codes were so old, when upgraded to php7, your website can fail to run, hence you should consider before upgrading it. If the CMS like WordPress, Magento then it is not worry, for WordPress, it should be version 4.3 and Magento is 1.9.2 or higher.

Install PHP 7 on CentOS

CentOS 6.x:

Code:
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
yum install yum-plugin-replace
yum replace php-common --replace-with=php70w-common
yum install php70w php70w-opcache php70w-mysql
CentOS 7.x:

Code:
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
yum install yum-plugin-replace
yum replace php-common --replace-with=php70w-common
yum install php70w php70w-opcache php70w-mysql
After that, check with php-v, if the output is:

PHP 7.0.0 (cli) (built: Jul 2 2015 18:38:21) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
Install PHP 7 on Ubuntu

Code:
sudo add-apt-repository ppa:ondrej/php-7.0
sudo apt-get update
If you are using Apache:

Code:
sudo apt-get install php7.0
sudo apt-get install php7.0-mysql
If you are using NGINX

Code:
sudo apt-get install php7.0-fpm
sudo apt-get install php7.0-mysql
Type php-v to check php version and if it is showing these

PHP 7.0.0-5+deb.sury.org~trusty+1 (cli) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
Important: If you are using NGINX

Apply for both CentOS and Ubuntu, when Upgrading to PHP 7, if you use NGINX then you need to edit NGINX config file then your websites run, see path location

install-php7-nginx.jpg

Install PHP 7 on CentOS and Ubuntu

Open NGINX config file and find the lines as following

Code:
location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
Restart NGINX:

Code:
service nginx restart
If you are using Apache then restart by this command

For Centos

Code:
systemctl restart httpd
For Ubuntu

Code:
service apache2 restart
Now you installed PHP 7 successfully on both CentOS and Ubuntu OS.
 
Recommended Threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top