Sunday, 28 August 2016

How to upgrade and install PHP 7 on ubuntu?

PHP 7, which was released on December 3, 2015, promises substantial speed improvements over previous versions of the language, along with new features like scalar type hinting.There have been a whole host of improvements made to PHP but we won’t delve too deep into changes. This is how to update to the latest release for those of you running a Ubuntu Linux system.

1. We need to do is add the ppa to our system, update the software sources and install our new version of PHP. 

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

sudo apt-get install php7.0-cli php7.0-common libapache2-mod-php7.0 php7.0 php7.0-mysql php7.0-fpm

Other packages which might be useful include:

sudo apt-get install php-mcrypt php7.0-soap php7.0-mbstring php7.0-intl php7.0-xml php7.0-curl php7.0-gd

Now you can check the php version using.

php -v

Result will like this.

PHP (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

2. Upgrading PHP-FPM with Nginx:

Install the PHP-FPM package.

sudo apt-get install php7.0-fpm

You'll be prompted to continue. Press Enter to complete the installation.

3. Install the mysql be sure for the PHP mysql bindings.

sudo apt-get install php7.0-mysql

Note: If you have made substantial modifications to any configuration files in /etc/php5/, those files are still in place, and can be referenced. Configuration files for PHP 7.0 now live in /etc/php/7.0.

4. Open the default configuration of nginx.

sudo nano /etc/nginx/sites-enabled/default

In the file fastcgi_pass unix:/var/run/php5-fpm.sock; changes to unix:/var/run/php/php7.0-fpm.sock

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/html;
    index index.php index.html index.htm;

    server_name server_domain_name_or_IP;

    location / {
        try_files $uri $uri/ =404;

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;

    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;

Save and exit the file and restart the nginx server.

sudo service nginx restart

Now check the your document root /usr/share/nginx/html or /var/www/html it may change according to your server configuration.

sudo nano /var/www/html/info.php


5. Now see the action on browser.

Featured post

How to create dynamic schema in mongodb

Sometime what we need in our application is to create mongodb schema for collection and some of our collection schema are same but names are...

Popular Posts