speed up your app by upgrading to php 7

Speed up your application by upgrading to PHP 7

Spread the love

In this tutorial, we are going to provide you with step by step instructions on how to install PHP 7 on an Ubuntu 16.04 VPS and on a CentOS 7 VPS. PHP 7 is the latest version of the PHP processing engine and it is faster than any other previous version of PHP. Also, PHP 7 consumes less memory.

Install PHP 7 on Ubuntu

Make sure your server OS packages are fully up to date by running the following commands:

sudo apt-get update 
sudo apt-get upgrade

Install PHP and commonly used PHP packages:

sudo apt-get install php7.0-cli php7.0-common php7.0-json php7.0-readline php7.0-xml php7.0-mysql php7.0-mcrypt php7.0-gd

To make sure that PHP 7 is installed on your server, run the following command:

sudo php -v

You should get an output like this:

PHP 7.0.13-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.13-0ubuntu0.16.04.1, Copyright (c) 1999-2016, by Zend Technologies

If you’d like to install additional PHP 7 modules, like OPCache for example, you can use the command below:

sudo apt-get install php7.0-opcache

In order to search for available PHP 7 modules, run:

sudo apt-cache search php7

To see which files are used by PHP in CLI mode, run:

# php --ini
Configuration File (php.ini) Path: /etc/php/7.0/cli
Loaded Configuration File:         /etc/php/7.0/cli/php.ini
Scan for additional .ini files in: /etc/php/7.0/cli/conf.d
Additional .ini files parsed:      /etc/php/7.0/cli/conf.d/10-mysqlnd.ini,

If you only want to locate your php.ini configuration file, use:

# php -i | grep -i php.ini
Configuration File (php.ini) Path => /etc/php/7.0/cli
Loaded Configuration File => /etc/php/7.0/cli/php.ini

The PHP Opcache extension can boost PHP performance by a large amount, so edit the PHP configuration file:

vi /etc/php/7.0/cli

Add the following lines in the ‘[opcache]’ section:


Do not forget to restart the web server for the changes to take effect:

service apache2 restart

Install PHP 7 on CentOS

Make sure that all OS packages are up to date:

yum clean all
yum update

Check if there are any installed PHP packages, e.g:

rpm -qa | grep php

Remove PHP 5.4 packages prior installing PHP 7:

yum remove php-cli php-pdo php-common php php-mysql

Add the required repositories:

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

Install PHP 7 and PHP 7 packages:

yum install php70w  php70w-cli php70w-mysql php70w-pdo php70w-common

To search for available PHP7 modules, run:

yum search php70w

You may install additional PHP extensions, like mycrypt, mbstring, OPCache etc.:

yum install php70w-opcache php70w-mcrypt php70w-mbstring

Check the PHP 7 version installed on your server:

#php -v
PHP 7.0.15 (cli) (built: Jan 19 2017 21:35:05) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.15, Copyright (c) 1999-2017, by Zend Technologies

To optimize PHP 7, locate the PHP configuration file and edit it:

#php -i | grep -i php.ini
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
vi /etc/php.ini

Add the following lines:

max_execution_time: 600
max_input_time: 600
max_input_vars: 5000
upload_max_filesize: 64M

Also, enable OPCache and configure it by adding the same settings in the ‘[opcache]’ section as on the Ubuntu 16.04 VPS.
Restart the Apache web server for the changes to take effect:

systemctl restart httpd

Of course, you don’t have to do any of this if you use one of our Software Installation services, in which case you can simply ask our expert Linux admins to install PHP 7 for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

3 thoughts on “Speed up your application by upgrading to PHP 7

Leave a Reply

Your email address will not be published. Required fields are marked *