PHP7: Install PHP7 with NGINX and MEMCACHE in Ubuntu 14.04

PHP7: Install PHP7 with NGINX and MEMCACHE in Ubuntu 14.04
by Date: 05-12-2018 php php7 nginx ubuntu linux memcache memcached


Let's install PHP7 and Nginx on a new Ubuntu 14.04 server, and manually build the (not yet packaged) memcached module for PHP7.

Command Rundown

Update: It looks like the php-memcached package was built into ppa:ondrej/php-php7.0 for php7, so the manual build steps is probably not necessary any longer! Install it via the package php-memcached.

Update2: The repository ppa:ondrej/php-php7.0 is being depreciated in favor of ppa:ondrej/php. I haven't had time to re-record the video, but I'll adjust the text of the article here.

First, we'll get the PHP-7 repository:

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

sudo apt-get update

Then we can install some tools and PHP7:

sudo apt-get install -y tmux curl wget \
    nginx \
    php7.0-fpm \
    php7.0-cli php7.0-curl php7.0-gd \
    php7.0-intl php7.0-mysql

    # php7.0-mcrypt is available, but is already compiled in via ppa:ondrej/php

# Since php-memcached is now available, install that too:

sudo apt-get install -y php-memcached

Then PHP7 is installed!


If we want to use it with Nginx, we just need to get the Nginx configuration up to date to use the PHP7.0-FPM's unix socket file path. (It's different from Nginx's default path).

server {
    listen 80 default_server;

    root /usr/share/nginx/html;
    index index.html index.htm index.php;

    server_name localhost;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php7.0-fpm:
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;

        fastcgi_index index.php;
        include fastcgi_params;


The php-memcached package should now be available for the latest Memcached library, so the following manual build steps is not necessary - but I'll leave it there just in case you're curious! Install it via sudo apt-get install -y php-memcached after adding the php7 repository.

If php-memcached was not installed, we can build it manually. (However, it's likely available to install via the php7.0-memcached package now).

If you need a newer version of the PHP-Memcached module, we can build it manually. Here's how:

First, we install some basics, including development packages for PHP and Memcached:

sudo apt-get install -y php7.0-dev git pkg-config build-essential libmemcached-dev

Then we can get the php-memcached repository, check out the php7 branch, and build it!

cd ~
git clone
cd php-memcached
git checkout php7
./configure --disable-memcached-sasl
sudo make install

The file gets installed into /usr/lib/php/20151012/.

Then we need to setup PHP (CLI and FPM) to use the memcached module. Edit /etc/php/mods-available/memcached.ini, add:

; configuration for php memcached module
; priority=20

Then enable it by including symlinks to that file in the FPM/CLI conf.d directories:

sudo ln -s /etc/php/mods-available/memcached.ini /etc/php/7.0/fpm/conf.d/20-memcached.ini
sudo ln -s /etc/php/mods-available/memcached.ini /etc/php/7.0/cli/conf.d/20-memcached.ini

# Reload php-fpm to include the new changes
sudo service php7.0-fpm restart

And there we have it, PHP7 is installed, with Memcached support!

by Date: 05-12-2018 php php7 nginx ubuntu linux memcache memcached hits : 8557  

Related Posts

Examine the 10 key PHP functions I use frequently

PHP never ceases to surprise me with its built-in capabilities. These are a few of the functions I find most fascinating.   1. Levenshtein This function uses the Levenshtein algorithm to calculate the…

How to Track Flight Status in real-time using the Flight Tracker API

The Flight Tracker API provides developers with the ability to access real-time flight status, which is extremely useful for integrating historical tracking or live queries of air traffic into your…

What is a JWT token and how does it work?

JWT tokens are a standard used to create application access tokens, enabling user authentication in web applications. Specifically, it follows the RFC 7519 standard. What is a JWT token A JWT token…

PHP - The Singleton Pattern

The Singleton Pattern is one of the GoF (Gang of Four) Patterns. This particular pattern provides a method for limiting the number of instances of an object to just one.…

How to Send Email from an HTML Contact Form

In today’s article we will write about how to make a working form that upon hitting that submit button will be functional and send the email (to you as a…

How To Use Varnish As A Highly Available Load Balancer On Ubuntu 20.04 With SSL

Load balancing with high availability can be tough to set up. Fortunately, Varnish HTTP Cache server provides a dead simple highly available load balancer that will also work as a…

The State of PHP 8: new features and changes

PHP 8.0 has been released last November 26: let's discover together the main innovations that the new version introduces in this language. PHP is one of the most popular programming languages…

HTTP Cookies: how they work and how to use them

Today we are going to write about the way to store data in a browser, why websites use cookies and how they work in detail. Continue reading to find out how…

How to install a Linux partition on a Windows 10 PC

In spite of a past we could say almost confronted, the approach between Windows and Linux is accelerating more and more, drawing a story closer to love than to hate.…

The most popular Array Sorting Algorithms In PHP

There are many ways to sort an array in PHP, the easiest being to use the sort() function built into PHP. This sort function is quick but has it's limitations,…

WSL2 is released to run Linux distributions on Windows

If you are reading about this for the first time, the Windows Subsystem for Linux is a kind of virtual machine that allows you to run the Linux terminal on…

MySQL 8.0 is now fully supported in PHP 7.4

MySQL and PHP is a love story that started long time ago. However the love story with MySQL 8.0 was a bit slower to start… but don’t worry it rules…