How to Install WordPress with LEMP Stack on an Ubuntu 14.04 Server

A bit about WordPress

Most’ve heard about WordPress by now, being one of the most used CMS(content management system) out there. It permits users of all levels of experience to easily create and manage blogs and sites.

In the following there will be a step by step guide on installing WordPress on a Ubuntu 14.04 server, using Nginx as a web server.

What you’ll need

Installing and configuring a LEMP (Linux operating system, Nginx, MySQL, and PHP) stack on your server. For the installation and setting up process, see the tutorial on installing a LEMP stack on Ubuntu 14.04.

Step 1 — Creating a MySQL Database and User for WordPress

After having installed the LEMP stack, we now have MySQL, but no database created for WordPress. So we’ll need to create one, along with a user account that will allow WordPress to access said database.

Begin by logging in with the following:

mysql –u root –p

Then you will be required to introduce the password you used for the root account when you installed MySQL , and afterwards a MySQL command prompt will be given.

Ok, now we’ll be moving on to creating a database that wil be used only by your WordPress application. Baptize your database wisely for easier recognition, in our case we called it wordpress.


A reminder for first time MySQL users, always make sure each statement ends with a semicolon ( ;).

Now we shall create that user account we’ve been talking about. This new user will have control of the database we created so that our application can interact with it. Creating a separate user and database for each app is an effective way for managing and keeping data secure in MySQL.

CREATE USER wordpressuser@localhost IDENTIFIED BY ‘password';

Now we need to make a connection between the user and database so that MySQL knows this new user can control the database:

GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;

Ok, now, for our current instance of MySQL to be up to date with the privilege change, we’ll need to flush the former ones:


Now exit:


Step 2 — Downloading WordPress to your Server

We need to download onto our server the WordPress content from the WordPress website. The URL is always the same for the latest stable version of WordPress. Download the file to our user’s home directory:

cd ~

The files have been downloaded in a compressed form stored in latest.tar.gz and we can extract the content with the following command which will create a directory named wordpress containing the files:

tar xzvf latest.tar.gz

To download additional components that we’ll be needing in WordPress, in this case packages that allow the user to work with images and install/update and manage plugins using SSH, we shall be using apt to get them from Ubuntu’s


sudo apt-get update
sudo apt-get install php5-gd libssh2-php

Step 3 — Configuring WordPress

Next we need to configure our WordPress instance by modifying the main configuration file in the directory we just made. First you need to get into said directory:

cd  ~/wordpress

Here we have a file called wp-config-sample.php that we can copy to use as a base for our confing file:

cp wp- config–sample.php  wp-config .php

Open the file so that we can make the necessary changes:

nano wp-config.php

Now we need to insert the information needed for us to connect to the database. First we need to set the DB_NAME, DB_USER, and DB_PASSWORD parameters, which you’ll find in this file and then we’ll set them to use the database and user
details created so far:

// ** MySQL settings - You can get this info from your web host ** //

define('DB_NAME', 'wordpress'); /** The name of the database for WordPress */
define('DB_USER', 'wordpressuser'); /** MySQL database username */
define('DB_PASSWORD', 'password'); /** MySQL database password */

After that, save and close the file.

Step 4 — Copying the Files to the Document Root

Now we need to copy our newly modified config files over to our document root so our server can find and do its thing.

For the transfer process we’ll be using rsync (which preserves permissions, ownership and data integrity) and we’ll need the location of the default document root of Nginx on Ubuntu 14.04 which is /usr/share/nginx/html.

We’ll set up our document root in /var/www/html/ to prevent us from modifying a directory location controlled by he nginx package (we’ll get to changing our nginx configuration later on).

Creating a new document root directory:

sudo mkdir  -p /var/www/html

Copy the files in the new document:

sudo rsync –avP ~/wordpress/  /var/www/html/

This will ensure that our content from ~/wordpress directory has been copied into our document root.

Now into the document root we go so we can make some adjustments:

cd /var/www/html/

The current directory structure allows user and group ownership of all our files to our regular user, but our web server only needs to be able to modify only some directories and files. So what now? We can give to the group that our web server runs under group ownership of the files permission so we can open them only when needed.

Nginx operates under the group called www-data. Enter your account name in the user portion( we’ll be using an account called bill:

sudo chown -R bill:www-data /var/www/html/*

Now we’re going to create a new directory for user uploads:

mkdir wp-content/uploads

Next we need to assign the new directory the www-data group ownership :

sudo chown –R :www-data /var/www/html/wp-content/uploads

Step 5 — Modifying Nginx Server Blocks

We need to change our nginx configuration to serve content appropriately. By using the default server block as a model for our new server block, we copy it over like so:

sudo cp /etc/nginx/sites-available/default  /etc/nginx/sites- available/wordpress

Open the new file for some changes:

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

Now for some more changes:

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

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


        location / {
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri&$args;

        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/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;

What we’ve done here is ( some of these changes might be set from your LEMP installation) :

  • changed the value of the root directory to point to the new document root at /var/www/html
  • modified the index parameter to search first for index.php files
  • changed value of server_name directive to point to your server’s name domain/IP address
  • adjusted the try_files from location / to make PHP aware if no exact match occurs.

Then save and close file.

Now we need to link the new file to the site-enabled directory to be able to activate it:

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/

We have to disable the old file so it doesn’t conflict with the new one we just linked:

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

To enable the chages we made we have to restart the web server and PHP processor :

sudo service nginx restart
sudo service php5-fpm restart

Step 6 — Completing the Installation through the Web Interface

After completing the aforementioned steps we’ll be finishing the installation through our web browser by pointing your browser to your server’s domain name or IP address:

This shows you your old default nginx page, you’ll sometimes have to refresh the page without the cache.
The installation process for WordPress is pretty straightforward; you choose your options(site name, username, email, password) and then just click on “Install WordPress”.

Next, the WordPress Dashboard should appear and you can start making the desired settings, content and stuff.

If you’ve followed these steps you should have your WordPress instance running on Ubuntu 14.04 with a nginx web server. WordPress has a very user friendly and accessible platform design, so now that you’re done with the trickier part of things, you can just go crazy and begin creating you site.

Want to host your WordPress website on a VPS? Then check out our high performance Linux Servers, starting at 2GB RAM for $5/mo.

Notify of
Inline Feedbacks
View all comments
× Dracula Servers

Subscribe to DraculaHosting and get exclusive content and discounts on VPS services.