Install WordPress with Nginx and Memcached Support on Ubuntu 17.04 | 17.10

This post shows students and new users how to install WordPress on Ubuntu 17.04 | 17.10 with Nginx and Memcached support. WordPress is probably the most installed content management systems today. To enhance and boost its performance, you may have to install tools like Memcached and others.

Memcached is a high performance in-memory caching system that can be used to speed up applications and websites that use databases. Memcached does not write to disk, instead store its content in system memory which makes it faster.

WordPress + Nginx + Memcached put together may boost your websites and applications.

When you’re ready, follow the steps below to get this working.

Step 1: Update Ubuntu

Before installing packages on Ubuntu systems you probably should first update the server. To do that run the commands below

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove

After running the commands above, you should probably restart the server.

Step 2: Install Nginx

After updating Ubuntu, run the commands below to install Nginx web server

sudo apt-get install nginx

When Nginx is installed, these commands can be used to stop, start and enable Nginx webserver to always start up when the server boots.

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

Step 3: Install MariaDB

After installing Nginx, run the commands below to install MariaDB Database server.

sudo apt-get install mariadb-server mariadb-client

After the installation, the commands below to stop, start and enable MariaDB server to always start up when the server starts

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Next, run the commands below to create a new password for MariaDB root user and secure the server

sudo mysql_secure_installation

You’ll be prompted with series of questions, follow the guide below to complete.

Enter current password for root (enter for none): PRESS ENTER

Set root password? [Y/n] Y

Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Step 4: Create WordPress Database

Now that MariaDB is installed, run the commands below to logon to the database server

sudo mysql -u root -p

You’ll be prompted to enter a root password. Type the one you created above for the root user.

Next, run the SQL commands below to create a database called wordpressdb.

CREATE DATABASE wordpressdb;

Run the commands below to create a new user named wpuser with new password, and grant the user access to the wordpressdb databases.

GRANT ALL ON wordpressdb.* TO 'wpuser'@'localhost' IDENTIFIED BY 'type_new_password_here';

After that, run the commands below to save your changes and exit.


Step 5: Install PHP and Related Modules

At this point Ubuntu, Nginx and MariaDB installed and WordPress database created. Nginx run the commands below to install PHP and Memcached

sudo apt-get install memcached php-memcache php-memcached php7.0-fpm php7.0-cli php7.0-fpm php7.0-curl php7.0-mbstring php7.0-mysql php7.0-gd php7.0-zip php7.0-intl php7.0-mcrypt libgd-tools libmcrypt-dev mcrypt php-pear libgd-dev php-pear php7.0-dev


Now that all the packages and server required by WordPress are installed, go and download WordPress content from online.

Use the commands below to do that.

cd /tmp && wget

Then run the commands below to extract the download folder and move WordPress content to Apache2 default document root on Ubuntu servers. The default document root is at /var/www/html.

tar -xzvf latest.tar.gz
sudo cp -R wordpress/* /var/www/html

Next, run the delete Apache2 default index.html file from document root.

sudo rm -rf /var/www/html/index.nginx-debian.html 


After Downloading WordPress, follow the steps below to configure WordPress with the database connecting settings created above.

First, run the commands below to create WordPress wp-config.php settings file from its sample.

sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

Then open wp-config.php file and make the following highlighted changes to reference the database and user you created above.

sudo nano /var/www/html/wp-config.php

When the file opens, make the changes and save.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpressdb');

/** MySQL database username */
define('DB_USER', 'wpuser');

/** MySQL database password */
define('DB_PASSWORD', 'new_password_here');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

After configuring WordPress settings, you next step will be to change Apache2 directory permissions so WordPress can function properly. To do that, run the below commands

sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

Next, open Nginx’s default configuration file by running the commands below

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

Then make change highlighted changes and save the file.

# Default server configuration
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;

        # 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.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass;

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #location ~ /\.ht {
        #       deny all;

Save the file and you’re done.

Now configure Memcached to suite your site. To do that open its configuration file from here

sudo nano /etc/php/7.0/mods-available/memcache.ini

After editing Memcached, save your changes, then run the commands to to restart Nginx, Memcached and and PHP-FPM

sudo service memcached restart
sudo service php7.0-fpm restart
sudo service nginx restart

Now Open your web browse and browse to the server IP or Hostname and you should see Ubuntu setup wizard page.

WordPress default setup page

Continue with the wizard until you’re done.

Congratulations! You’ve just installed WordPress with Nginx, Memcached support on Ubuntu


You may also like the post below:

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.