Installing WordPress with Nginx on Ubuntu 14.04

In Linux Tutorials

Install WordPress with Nginx on Ubuntu 14.04

Installing WordPress with Nginx on Ubuntu 14.04 is a fairly straightforward task. In this tutorial we will do over how to do it. This tutorial assumes you have completed the Getting Started with an Ubuntu VPS guide and have an Ubuntu 14.04 VPS (if not you can get one here for $5). It also assumes that you already have a LEMP stack setup (Linux, Nginx, MySQL, etcetera) or you are following the Making WordPress Fly guide. This tutorial assumes the use of Nginx as the web server, Fastcgi or HHVM for PHP and either MariaDB or MySQL  for your MySQL server.

The first step in this tutorial is to connect to your virtual machine via SSH. This tutorial assumes that you are using Linux as your operating system and have SSH installed. If you do not you can use a tool like Putty for SSH. In Linux you just need to run the following command:

After connecting to your instance via SSH it is time to begin the process of installing WordPress to work with Nginx. All of our tutorials for Nginx assume a “web root” of  /var/www/html, make sure that your Nginx configuration points there and that the directory exists. If the directory does not exist create it using  mkdir and chown  it to www-data .

Creating a Database and User

After you have confirmed that Nginx is using /var/www/html/ as your web root or setup another of your choice, it’s time to create a database for WordPress. Please make sure you have already setup MySQL or MariaDB prior to this step. Setting up the database is easy. Start by logging into an interactive session with the MySQL administrative account.

You will be prompted for the root password you setup during MySQL installation. Enter it and proceed to the interactive prompt. Next we are going to create a database for WordPress to use and store information in. The name of the database does not matter, but it should be memorable so that you can distinguish it as you add additional databases later on. To do this simply run this command:

Note the semi-colon (;) that ends the MySQL statement. Every MySQL statement must end with one, so check that if you are running into issues. Now that you have created a database, we need to create a user. You are going to use the same interactive interface you are in now to create a user. Use this command:

Make sure you replace ‘password’ with the database password you want to use and ‘wordpressuser’ with the name of the database user you want to create. After that is done you need to assign that user privileges to use the database we just created. Use this command:

Make sure you replace the database name and username with the ones you created. Everything should now be configured correctly. We need to flush the privileges (save them to disk) so that our current instance of MySQL knows about the privilege changes we have made:

Now you can exit MySQL:

At this point you are back at the shell command prompt and ready to continue.

Installing WordPress with Nginx on Ubuntu 14.04

The next step is to download the latest version of WordPress to the server. It is available on their website. We are going to use the  wget  command to copy it to our home directory.

WordPress always keeps the latest stable version at the place we will use in this command.

The files which compose WordPress were downloaded as a compressed archive stored in a file called latest.tar.gz. We can extract the contents by typing:

This will extract a directory called wordpress  containing all the files we need to set up WordPress. First however make sure that  php5-gd  and libssh2-php are installed. If they are not, run the command below. This will make sure you can work with images and install modules/plugins over SSH.

Configuring WordPress with Nginx on Ubuntu 14.04

Now we are ready to configure WordPress and move it into the web root. Let’s move into the directory that we extracted WordPress to in the last section:

Now we want to copy the sample configuration to take the place of the non-existent main configuration.

Next we need to make 3 small changes to wp-config.php  using nano  or your text editor of choice.

The file is suitable for launching WordPress; it is just lacking the information to connect to the database we created a few minutes ago. The parameters we need to set are DB_NAME , DB_USER , and  DB_PASSWORD .

After you make the changes to that section of the file it should look something like this:

For now you can ignore the rest of the site. If you are planning on deploying a multisite network add this line:

Once you have made these changes you can save and close the file. Now it is time to copy the files to our web root ( /var/www/html/  in this example). We can copy the files to this place by typing:

Now we need to move over to that folder to assign some permissions.

Then we are going to make sure that Nginx owns these files so that it can manipulate them.

Before we move on, we should create a new directory for user uploads:

The new directory should have group writing set already, but the new directory isn’t assigned with www-data group ownership yet. Let’s fix that:

Now just make sure that your web server is configured to use /var/www/html/ as the webroot and you can visit yourdomain.com to set your site name and get started. You are also going to want to install Postfix so that WordPress can send emails. We will be writing a tutorial for that in the near future.

Thanks for reading and leave your thoughts in the comments below.

5 Comments

  1. you may also want to
    Add writable permission to the group
    $ chmod g+w /wp-contents/uploads
    or
    $ chmod 775 /wp-contents/uploads

  2. I read your articles on the server to optimize WordPress and liked.
    The last I read was: INSTALLING WORDPRESS WITH NGINX ON UBUNTU 14.04.
    I wonder if it would be possible to create a supplement to this article showing how to set up WordPress and Ubuntu, so we can install / update plugins for wp-admin, update the WP install themes, etc …

  3. I think I have the same problem friend above.
    I followed all the steps, but when trying to install a plugin, the following screen appears:
    http://i.imgur.com/tgujyzK.png

    I installed Ubuntu in a vm with Ubuntu 14.04, with OpenSSH, and then followed all the steps of the tutorial. Not want to use FTP, for security reasons, I prefer sftp.
    ———-
    I noticed that WordPress is much faster, I’m thinking of installing some library cache for php like APC or eAccelerator to speed up even more, do you recommend any?

  4. I have followed all of the instructions from part 1 to part 4. I can successfully access mywebsite.com/wp-login.php but after that I’m getting a Forbidden 403 error. I’ve been looking around on the web but can’t seem to figure out what is causing that… any ideas? Thanks

Submit a comment