How To Upgrade to PHP 7 on Ubuntu

Sep 26, 2017 PHP
Upgrade PHP 5 to PHP 7 on Ubuntu | Learn2torials

PHP7 was released on December 3, 2015. In this blog you will learn how to install php7 on ubuntu and install it's dependecy for fpm, apache and nginx.

Followings are some of the advantages of PHP7

  • Speed improvements over previous versions.
  • Scalar Type Declarations.
  • Return Type Declarations.
  • Uniform Variable Syntax
  • Asynchronous Programming Speculation

Follow the commands below to install PHP7 on Ubuntu

// add ppa for php7
$ sudo add-apt-repository ppa:ondrej/php;

// update the local packages
$ sudo apt-get update;

// install php7
$ sudo apt-get install php7.0;

// update mysql dependecy for php7
$ sudo apt-get install php7.0-mysql;

// upgrade fpm
$ sudo apt-get install php7.0-fpm;

Nginx Virtual Host file update

For those, who run php-fpm it is necessary to upgrade the socket configuration in virtual host file as seen below.

// open the default virtual host file
$ sudo nano /etc/nginx/sites-available/default;

// replace fastcgi_pass unix:/var/run/php5-fpm.sock;
// with    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock
server {

    server_name server_domain_name_or_IP;
	root /var/www/html;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ =404;

    location ~ ^/(app|app_dev|config).php(/|$) {
    	try_files $uri =404;
    	fastcgi_split_path_info ^(.+.php)(/.+)$;
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        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;

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;

// restart nginx
$ sudo service nginx restart;

// check the current php version
$ php -v;
Rate This Article

What is PHP7? How to upgrade from php 5 to php 7 on ubuntu?


About Author