Install WordPress with LEMP on Ubuntu 16.04


WordPress is the most popular CMS (content management system) on the internet. It allows you to easily set up flexible blogs and websites on top of a MySQL backend with PHP processing. WordPress has seen incredible adoption and is a great choice for getting a website up and running quickly. After setup, almost all administration can be done through the web frontend.

In this guide, we’ll focus on getting a WordPress instance set up on a LEMP stack (Linux, Nginx, MySQL, and PHP) on an Ubuntu 16.04 server.



  1. You should have non-root user with sudo privileges. For that, you have to create a user and then grant the sudo privileges to the user.
  2. You should have installed the LEMP stack on your Ubuntu 16.04 server. Refer this initial server setup guide

When you are finished the setup steps, log into your server as your sudo user and continue below.


Step 1: Create a MySQL Database and User for WordPress

The first step that we will take is a preparatory one. WordPress uses MySQL to manage and store site and user information. We have MySQL installed already, but we need to make a database and a user for WordPress to use.

To get started, log into the MySQL root (administrative) account by issuing this command:

You will be prompted for the password you set for the MySQL root account when you installed the software.

First, we can create a separate database that WordPress can control. You can call this whatever you would like, but we will be using wordpress in this guide to keep it simple. You can create the database for WordPress by typing:

Next, we are going to create a separate MySQL user account that we will use exclusively to operate on our new database. Creating one-function databases and accounts is a good idea from a management and security standpoint. We will use the name wordpressuser in this guide. Feel free to change this if you’d like.

We are going to create this account, set a password, and grant access to the database we created. We can do this by typing the following command. Remember to choose a strong password here for your database user:

You now have a database and user account, each made specifically for WordPress. We need to flush the privileges so that the current instance of MySQL knows about the recent changes we’ve made:

Exit out of MySQL by typing:



Step 2: Configuring Nginx for WordPress

You’ll now need to configure Nginx to deliver traffic to the future WordPress installation. Start by creating a new server block for Nginx.

Then you can paste the following into this new file and save it.

Do not forget to replace ‘’ with your actual domain name.

This is a fairly standard nginx+Wordpress server block to get you up and running. It doesn’t come with caching or gzip bells and whistles, but those are beyond the general scope of this tutorial. The WordPress Codex has some additional options if you’re interested.

Be sure to test the configuration to ensure that it will function correctly.

Enable the new WordPress server block by creating a link between the sites-available and sites-enabled directories.

If you don’t see any errors, you can reload nginx.



Step 3: Installing the WordPress

Now that our server software is configured, we can download and set up WordPress. For security reasons in particular, it is always recommended to get the latest version of WordPress from their site.

Change into a writable directory and then download the compressed release by typing:

Extract the compressed file to create the WordPress directory structure:

Now you can copy all the files to the server root.

The last step is configuring permissions for the server root. By giving permissions to the www-data user, you’ll be able to get automatic updates and more.

Finally, you can navigate to your server’s IP address to begin the famous 5-minute WordPress installation.




Nginx configuration differs a lot. You have to be careful while adding and removing the location blocks.

Also, you don’t need to worry about the Nginx WordPress htaccess file. Nginx doesn’t process the htaccess file.

We will How to setup WordPress Nginx Multisite in the upcoming article.

If you still have any doubt in installing WordPress on LEMP stack, let us know that in the command.