Nginx + WordPress

An Easy-To-Follow Guide in Setting Up WordPress with Nginx on Ubuntu 14.04 Server (LEMP)

Running WordPress on an Ubuntu 14.04 with Nginx as your web server application is a solid box setup to host your blog in a VPS with minimal resources.

Summary:

  1. Initial Server Setup
  2. Install CSF
  3. Install LEMP
  4. Configure Nginx Server Blocks
  5. Install Free SSL Using Let’s Encrypt
  6. Install WordPress
  7. Sources

 

1. Initial Server Setup

The installation and configuration of the necessary software would be as easy as 1-2-3 when you follow the ste-by-step guide in this post. This section will tackle the initial server configuration using DigitalOcean’s 512MB Droplet ($5 per month plan). Get a free $10 credit when you register using this link.

Fire up your Droplet with Ubuntu 14.04 as your base OS. Do not use a private key for the meantime. The root password would be sent to your email. Once you have booted your Droplet, connect to it using through ssh.

 

The very first thing we need to do after logging into your box is to create a non-root user and grant it sudo privileges.

Replace USERNAME with your username of choice.

 

Edit your BASH profile (~/.profile) to add timestamp to your history and avoid duplicates.

Note: PS1 changes are just cosmetic customization of your BASH prompt. Edit as you like.

 

Adjust your timezone. I prefer using UTC as a standard time of all my servers.

In the setup screen, choose the timezone you prefer. You may set it to your local timezone if that’s what you prefer.

 

Secure your SSH server by removing it off from the default port which is port 22. You may choose whatever non-common port number you like. You may want to choose a number between 1024-65535. Open your ssh config file /etc/ssh/sshd_config and edit the following

Replace CUSTOM_PORT with any port number you like. I advise you not to use any of the well-known ports.

 

Finally, update your server.

 

2. Install CSF

Config Server Firewall (CSF) is a free firewall management software designed for Linux distributions. In this section, we would install CSF as well as configure the basic settings and enable its User Interface panel which you can access using your web browser.

First, we need to disable the default firewall configuration tool that comes with Ubuntu.

 

Next, let us download the latest CSF release from their website.

 

After the installation, let’s go ahead and edit some basic settings in its configuration file /etc/csf/csf.conf.

Change the UI_USERNAME, UI_PASSWORD, and UI_PORT as you like.

 

Now let us install the CSF UI dependencies.

 

Finally, reload CSF and restart LFD.

You would now be able to access your CSF UI by going to

https://SERVER_PUBLIC_IP:UI_PORT

 

 

 

3. Install LEMP (Nginx, MariaDB, PHP)

Normally, users would choose to install Apache instead of Nginx due to its popularity. However, I decided to install Nginx on the 512MB Droplet due to its tight resources. Out-of-the box, Nginx uses less resources compared to Apache. Let’s proceed in installing these software to get our server ready in hosting our WordPress website.

Login using the non-root user you created in first step of this guide. Install the Nginx from the Ubuntu repository.

 

Next, we install MariaDB (or MySQL). I prefer using MariaDB due to its speed and performance improvements over MySQL. Below are two separate steps you could follow depending on whichever you decided to install.

# MariaDB Installation

# MySQL Installation

 

Nginx does not include a native PHP processor. Thus, we need to install php5-fpm.

 

Edit the configuration file /etc/php5/fpm/php.ini and find the following line and set it to “0”

 

Now let us configure Nginx to use the newly installed PHP Processor

Make sure to add index.php and edit SERVER_DOMAIN_NAME_or_PUBLIC_IP to match your domain name or IP address. Also add the block of text highlighted in red inside your server block.

 

Finally, restart Nginx and PHP-FPM afterwards. I encountered an issue where the PHP processor is not working properly. If that is the case. Restart your server to fix it.

 

Leave a Reply