How to install or upgrade PHP 5 to PHP 7

In this tutorial we will walk you through on how to install or upgrade php to PHP 7, this instructions are for those who run a server with a LEMP (Linux, Nginx, Mysql and PHP) configuration. our server is running on Ubuntu 14.04 LTS and PHP 5.9.

The first thing you need to do is add the repository that has PHP7 for Ubuntu using this command:

sudo add-apt-repository ppa:ondrej/php

You’ll see a description of the PPA, followed by a prompt to continue. Press Enter to proceed.

Once the PPA is done installing you need to update your package listings:

sudo apt-get update

Now we are ready to install PHP 7 and its mysql binding:

sudo apt-get install php7.0-fpm php7.0-mysql

We are almost there, now we need to change the path to the fastcgi_pass to the new php 7 location by replacing “/var/run/php5-fpm.sock” with “/var/run/php/php7.0-fpm.sock” in your server block php location, your php location will look something like this:

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;

To finish we just need to restart nginx:

sudo service nginx restart

That’s it! you are now running PHP 7 in all it’s glory, you may want to check out the official installation documents over at

« Back To News

Comments are closed.