1. Home
  2. Tutorials
  3. How To Install WordPress with Nginx on Ubuntu 14.04

How To Install WordPress with Nginx on Ubuntu 14.04

How To Install WordPress with Nginx on Ubuntu 14.04
How To Install WordPress with Nginx on Ubuntu 14.04

Tutorial Introduction

WordPress is a very popular CMS (content management system) in the world. It grants you the ability to get your site or blog up and running easily.

Once you’ve installed WordPress, you could manage just about anything in an easy web interface.

In this tutorial we are going to show you how you can install WordPress on your Ubuntu 14.04 server. We’ll be using nginx for the web server component, It’s quite powerful and efficient, it’s one of the most popular web server components due to its performance capabilities.


Before starting with the tutorial, there are a couple things that you are required to have.

  1. You’ll require a non-root user with sudo privileges.
  2. You’re also going to need a LEMP (Linux operating system, Nginx web server, MySQL database, and PHP processing) stack installed and configured on your server.

Once you’ve gotten the requirements you may proceed with the tutorial.

Create a MySQL Database and User for WordPress

The way we get started with WordPress is by first preparing the database.

We’ve got the MySQL database software installed, but we’ve not made a database for our WordPress information. We are going to have to create an account which WordPress will use in order to access the database we will be making.

We will start by logging into an interactive session using our MySQL administrative account by using the following command:

mysql -u root -p

You are going to be asked for the password you’ve chosen for the MySQL root account after you installed the software. You should be receiving a MySQL command prompt.

Then, we will create a separate database which is going to be used only by our WordPress application.  The name shouldn’t matter, just make sure it’s descriptive so you could recognize it easily.

In this tutorial we are going to call our database wordpress:


Keep in mind that the semi-colon (;) is what ends the MySQL statement. Every MySQL statement has to end with one, so make sure of that in case you ever run into any issues.

Now we’ve got a database, so we can now create a user account. Afterwards we will hand over control of the database to this new user so that our application may interact with the database. That system of creating a separate database and user for every application helps ensure our data is separate from other data being stored by MySQL, this is great for security and data management.

For this tutorial, we will use wordpressuser as an account name. We will give it a password of ‘password’ to authenticate with. Once you’ve set up your own configuration, you will need a more secure password:

CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';

Since we’ve got ourselves a database and a user, we can now establish a relationship between the two.

We start by telling MySQL that our new user is allowed to access and control the database. You could do this using the following command:

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

Now everything should be configured and ready. We will also have to flush the privileges to disk so that our current instance of MySQL knows about the privilege changes we’ve done:


Next, quit the MySQL prompt:


We will now be back in our command prompt and ready to proceed.

Download WordPress to your Server

Next, we’ll want to download the actual WordPress content onto our server. This will be available on the WordPress website.

The latest stable version of the application is always provided with the same URL, that should make this part easy. We should download the file to our user’s home directory:

cd ~

wget http://wordpress.org/latest.tar.gz

The application files are usually downloaded as a compressed, archived directory structure stored in a file named latest.tar.gz. You may extract the contents by executing the following:

tar xzvf latest.tar.gz

This will make a directory named wordpress which contains the site files.

We will want to take this chance to download some more components that our WordPress instance is going to require. We could get those directly from Ubuntu’s software repositories using apt:

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

Those two packages will grant you the ability to work with images and be able to install/update plugins and components using SSH respectively.

Configure WordPress

Since we now have the files we may start configuring our WordPress instance.

We have to edit the main configuration file located in our new directory. Go into the directory that you extracted to in the last part:

cd ~/wordpress

Within this directory we have a sample configuration file named wp-config-sample.php. This will have most of the configuration details right, so we may copy that to use as the base of our config file:

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

Once we’ve opened the file, the first thing we’ll want to do is adjust some secret keys to provide some security for our installation. WordPress gives a secure generator for those values so you won’t have to try and come up with good values on your own. Those should only be used internally, so it isn’t going to hurt usability to have complex, secure values here.

To get secure values from the WordPress secret key generator, use the following:

curl -s https://api.wordpress.org/secret-key/1.1/salt/

You will receive unique values that look like the below:


define('AUTH_KEY',         '1jl/vqfs<XhdXoAPz9 DO NOT COPY THESE VALUES c_j{iwqD^<+c9.k<J@4H');

define('SECURE_AUTH_KEY',  'E2N-h2]Dcvp+aS/p7X DO NOT COPY THESE VALUES {Ka(f;rv?Pxf})CgLi-3');

define('LOGGED_IN_KEY',    'W(50,{W^,OPB%PB<JF DO NOT COPY THESE VALUES 2;y&,2m%3]R6DUth[;88');

define('NONCE_KEY',        'll,4UC)7ua+8<!4VM+ DO NOT COPY THESE VALUES #`DXF+[$atzM7 o^-C7g');

define('AUTH_SALT',        'koMrurzOA+|L_lG}kf DO NOT COPY THESE VALUES  07VC*Lj*lD&?3w!BT#-');

define('SECURE_AUTH_SALT', 'p32*p,]z%LZ+pAu:VY DO NOT COPY THESE VALUES C-?y+K0DK_+F|0h{!_xY');

define('LOGGED_IN_SALT',   'i^/G2W7!-1H2OQ+t$3 DO NOT COPY THESE VALUES t6**bRVFSD[Hi])-qS`|');

define('NONCE_SALT',       'Q6]U:K?j4L%Z]}h^q7 DO NOT COPY THESE VALUES 1% ^qUswWgn+6&xqHN&%');

We may now paste these configuration lines directly into our configuration file to set secure keys. Copy the output you’ve received.

Next, click the WordPress configuration file:

nano wp-config.php

Look for the section which contains the dummy values for these settings. It should look like this:

. . .

define('AUTH_KEY',         'put your unique phrase here');

define('SECURE_AUTH_KEY',  'put your unique phrase here');

define('LOGGED_IN_KEY',    'put your unique phrase here');

define('NONCE_KEY',        'put your unique phrase here');

define('AUTH_SALT',        'put your unique phrase here');

define('SECURE_AUTH_SALT', 'put your unique phrase here');

define('LOGGED_IN_SALT',   'put your unique phrase here');

define('NONCE_SALT',       'put your unique phrase here');

. . .

Remove these lines and paste in the values you’ve copied from the command line:

. . .









. . .

The file is now suitable for our needs; all it requires now is the information to connect to the database we’ve made. The parameters we have to set are DB_NAME, DB_USER, and DB_PASSWORD.

We could find those parameters in the following file and set them up to use the database and user details that we’ve made. This is an example of what we have in the file:

. . .

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

/** The name of the database for WordPress */

define('DB_NAME', 'wordpress');

/** MySQL database username */

define('DB_USER', 'wordpressuser');

/** MySQL database password */

define('DB_PASSWORD', 'password');

. . .

After you’ve made the changes above, save and exit the file.

Copy the Files to the Document Root

Now that we’ve done our changes to the config files. The next thing we need to do is copy them over to our document root so that our web server will find them and serve them.

We are going to use the rsync utility to do the transfer. It will have the advantage of preserving permissions, ownership, and ensuring data integrity.

The location of the default document root of nginx on Ubuntu14.04 is located in /usr/share/nginx/html/.

But, we will be setting up our document root in /var/www/html/ to avoid editing a directory location which is controlled by the nginx package. We are going to change this in our nginx configuration a little later.

We may create the new document root directory by using the following:

sudo mkdir -p /var/www/html

Next, we may copy the files to this location by using the next command:

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

This should recursively copy the contents of our ~/wordpress directory into our document root.

We will now move over to the document root so we may adjust certain permissions:

cd /var/www/html/

The problem with the directory structure as it stands currently is that all of ur files have user and group ownership attached to our regular user. This is okay, except that our web server has to be able to edit some directories and files.

We could grant this permission without exposing too much of our system by providing the group that our web server runs under group ownership of the files. Afterwards we may open up group permissions slightly as required.

The group which nginx operates under is www-data. As for the user portion, type your user account name. We are going to demonstrate using an account named userdemo here:

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

This should grant our files the required ownership.

Before moving on, we need to create a new directory for user uploads:

mkdir wp-content/uploads

The new directory will have group writing set already, however the new directory isn’t assigned with www-data group ownership yet, so let’s change that:

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

Modify Nginx Server Blocks

Since our files and directories are configured, we will proceed to modifying the nginx configuration so it serves the content correctly.

We could use the default nginx server block as a base for our new server block. Copy it over exactly like the below command:

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

Open the new file we’ve created so we could do a couple changes to it:

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

We are going to want to do the next changes:

server {

        listen 80 default_server;

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

        root /var/www/html;

        index index.php index.html index.htm;

        server_name your_domain.com;

        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;



A summary of things you will need to change:

  1. Modify the value of the root directive to point to our new document root at /var/www/html.
  2. Edit the index parameter so it searches for an index.php file before any other files
  3. Modify the value of the server_name directive so it points to your server’s domain name or IP address.
  4. Change the try_files inside the location / block so it sends requests to PHP when they aren’t an exact match.

A couple of these might already be set because of your LEMP installation. Once you are finished with those changes, save and exit the file.

We’ll have to link our new fle to the sites-enabled directory in order to enable it. We may do it like this:

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

The file we’ve just linked conflicts with our old default file, because it borrowed a lot from it. We have to disable the old file:

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

Next, restart the web server and the PHP processor for the changes to take effect:

sudo service nginx restart

sudo service php5-fpm restart

Complete the Installation through the Web Interface

Since our wordpress is ready to go, we may finish the installation from our web browser

Point your browser to your server’s domain name or IP address, like the example below:


IN case this shows your old default nginx page, you might want to refresh the page without the cache.

You should see the basic WordPress welcome stage. Select your options (Site name, username, password, and email) afterwards click the install WordPress button.

Next you will need to login with the account you’ve just made:

Then you will be presented with your WordPress dashboard, there you can start customizing your setup and creating content.


You will now have your WordPress instance up and running on an Nginx web server in Ubuntu 14.04.

WordPress is a very flexible platform which you could use to customize your site. Test with several plugins, themes, and more, to find out which one works best for you.

Updated on January 6, 2018

Was this article helpful?

Related Articles

Add A Comment