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!

Nginx

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;
    }
}

Memcached

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 https://github.com/php-memcached-dev/php-memcached.git
cd php-memcached
git checkout php7
phpize
./configure --disable-memcached-sasl
make
sudo make install

The memcached.so 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
extension=memcached.so

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 : 5584  
 
 
 
 

Related Posts

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…

Linux For Dummies: Permissions

In the previous articles I made a short introduction to the Unix world and in the following article I have dealt with the basic commands for the file system management. Today we are…

Linux for Dummies: Ubuntu Terminal

I introduced in the previous article, available here, the basic concepts concerning the Linux world. Today we are going to have a look to some basic operations that we can perform…

Linux for Dummies: Introduction

If you have thought about migrating from Windows to a Unix operating system, or Linux specifically there are things you should know. The goal is to give essential information (and…

The Best RSS Readers for Ubuntu

Even if most of the tech experts actively claim that RSS (Rich Site Summary) is dead especially after Google Reader was discontinued 5 years ago but it isn’t yet as…

A roadmap to becoming a web developer in 2019

There are plenty of tutorials online, which won't cost you a cent. If you are sufficiently self-driven and interested, you have no difficulty training yourself. The point to learn coding…

80 Linux Network Monitor Software & Tools for Managing & Monitoring Unix/Linux Systems

It’s hard work monitoring and debugging Linux performance problems, but it’s easier with the right tools at the right time. Finding a Linux Network Monitor tool or Software package for…

How to install Letsencrypt Certificates with Certbot in Ubuntu

In this article we will explain how to install, manage and configure the SSL Security certificate, Let's Encypt in NGINX server used as proxy. This certificate is free but does…

We use our own and third-party cookies to improve our services, compile statistical information and analyze your browsing habits. This allows us to personalize the content we offer and to show you advertisements related to your preferences. By clicking "Accept all" you agree to the storage of cookies on your device to improve website navigation, analyse traffic and assist our marketing activities. You can also select "System Cookies Only" to accept only the cookies required for the website to function, or you can select the cookies you wish to activate by clicking on "settings".

Accept All Only sistem cookies Configuration