Install Nginx with PHP-FPM and Memcached Support on Ubuntu 17.04 | 17.10

Nginx with PHP-FPM and Memcached support allows for improved websites and web applications performance. Memcached is a free open source high-performance object caching program… it allows repeated PHP object / database calls to be cached in system memory to help speed up dynamic web applications.

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

Using Memcached with Nginx, PHP-FPM on your WordPress or other CMS websites or blogs is a great way to improve their performance. Memcached is a simple yet powerful caching program that webmasters and website owners should use if possible.

This brief tutorial is going to show students and new users how to install Nginx, PHP-FPM and Memcached on Ubuntu 17.04 | 17.10.

To get started follow the steps below:

Step 1: Install Nginx

Run the commands below to install Nginx webserver on Ubuntu

sudo apt update
sudo apt install nginx

After installing Nginx, the commands below can be used to stop, start and enable Nginx to always start up when the system boots

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Step 2: Install Memcached

After installing Nginx above, run the commands below to install Memcached.

sudo apt install memcached

After installing Memcached, the commands below can be used to stop, start and enable Memcached.

sudo systemctl stop memcached.service
sudo systemctl start memcached.service
sudo systemctl enable memcached.service

Step 3: Install PHP-FPM with Related Nginx Memcached Modules

Now that Nginx is installed, run the commands below to install PHP with Nginx and Memcached modules.

sudo apt-get install php-fpm php-memcached php-cli

The commands above will install the necessary PHP modules to enable Memcached to function and be accessible.

To enable Nginx PHP site support, open its default site configuration file and enable the PHP block…..

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

Then remove the comment to enable the PHP section..

server {
	listen 80 default_server;
	listen [::]:80 default_server;
        ............
        ............

        index index.php index.html index.htm;

        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            #
            # # With php-fpm (or other unix sockets):
            fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;        #Ubuntu 17.10
          # fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;        #Ubuntu 17.04
           # # With php-cgi (or other tcp sockets):
           # fastcgi_pass 127.0.0.1:9000;
  }
  ..........

Restart Nginx Webserver

sudo systemctl reload nginx.service

This is how to get Nginx with PHP-FPM and Memcached support. Now to see if Memcached is installed, run the commands below to create a test php file.

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

Then copy and paste the content below into the file and save.

<?php
phpinfo();
?>

Save the file. After saving, open your browser and browse to the server hostname or IP address followed buy phpinfo.php

example:  http://192.168.2.1/phpinfo.php

You should see all the PHP related modules as well as memcached information. When you see the screenshot below, then you’ll Memcached is installed and enabled.

memcached ubuntu install

Congratulations! You’ve successfully installed Nginx, PHP-FPM and Memcached on Ubuntu 17.04 | 17.10 systems.

Memcached configuration file is located at /etc/memcached.conf

Run the commands below to open it… there you can change some parameter values to suit your environment

sudo nano /etc/memcached.conf

PHP can be configured at /etc/php/7.x/fpm/php.ini

sudo nano /etc/php/7.x/fpm/php.ini

Change settings there also to suit your environments

Enjoy!

You may also like the post below:

Migrate Joomla Websites on Ubuntu 17.04 / 17.10 with Nginx, MariaDB and PHP Support

One Reply to “Install Nginx with PHP-FPM and Memcached Support on Ubuntu 17.04 | 17.10”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.