In this tutorial, we’ll see how to install and configure WordPress on a LEMP stack, with Ubuntu 16.04, Nginx, MySQL and PHP 7.0. To check the previous steps of this series of tutorials, you can check the following pages:

If you’re up to date, let’s go on with the install of WordPr ess! As usual we use “example.com” as an example. To follow the tutorial, you’ll have to replace example.com with your own site.

1. Log in to the terminal and create a directory called src under your website’s directory. This is where we will fresh copies of WordPress’s source files:

sudo mkdir /var/www/example.com/src/

2. Navigate to the newly created folder:

cd /var/www/example.com/src/

3. Set your web server’s user, www-data, as the owner of your site’s home directory:

sudo chown -R www-data:www-data /var/www/example.com/

4. Get the latest version of WordPress:

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

5. Extract it:

sudo -u www-data tar -xvf latest.tar.gz

6. Rename latest.tar.gz as wordpress followed by the date to store a backup of the original source files. This will be useful if you install new versions in the future and need to revert back to a previous release:

sudo mv latest.tar.gz wordpress-`date "+%Y-%m-%d"`.tar.gz

7. Move the WordPress files to your public_html folder:

sudo mv wordpress/* ../public_html/

8. Give your web server ownership of the public_html folder:

sudo chown -R www-data:www-data /var/www/example.com/public_html

9. Go to this URL to start the WordPress set up on your website:

https://www.example.com/wp-admin/setup-config.php

We’ll now proceed to the famous “5-Minutes Install” of WordPress.

10. First, choose the language of the install. Here we’ll stick to english.

Choose the language in which to install WordPress

11. On the next page, WordPress will remind you the different informations needed for its own configuration. The should already have noted all these informations, when you created the MySQL database. You just have to click on the “Let’s Go” button to proceed to the next step.

WordPress installation: Let's Go! | Palawan Digital

12. On the next page, you’ll have to indicate the database name, username, password, host (usually, it should be left on localhost) and change the table prefix (whether you plan on running one or several WordPress installs on the database, this is a slight precaution worth taking).

WordPress Install - Indicate the name, username, password and host of the database | Palawan Digital

Click on “Submit” when it’s done.

13. If all the informations are correct, you’ll see this message and you’ll just have to click on “Run the install” to proceed to the install of WordPress.

Run the install of WordPress | Palawan Digital

13. On the following page, you’ll have to indicate the website’s name, your username (tip: make it something unique, not “admin” or the website’s name), and generate a password. On the next page, you will be able to login to your new install of WordPress.

That’s all for the install of WordPress itself. Now, we’ll get to tweak some things to make it work correctly with our Nginx server.

14. By default, WordPress will prompt you for FTP credentials when you install new themes or plugins. To bypass this, modify your wp-config.php file by adding the following lines:

nano /var/www/html/example.com/public_html/wp-config.php

15. Add this to the file:

/** Bypass FTP */
define('FS_METHOD', 'direct');

16. Also add this line:

/** Memory Limit */
define( 'WP_MEMORY_LIMIT', '256M' );

17. Nginx needs to be directed to check whether the page each permalink refers to exists. By default, nginx assumes that it doesn’t, and returns a server-side 404. Update the following lines in the location / { block of your virtual host configuration:

nano /etc/nginx/sites-available/example.com

18. Write this:

location / {
    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?$args;

That’s it, WordPress is installed and ready to work on your Nginx web server! But we’re going to configure the server a bit more so that your WordPress can manage a premium theme, let you upload larger files and few other tricks.

19. Open the PHP configuration files:

nano /etc/php/7.0/fpm/php.ini

20. Verify that the following values are set. All of the lines listed below should be uncommented. Be sure to remove any semicolons (;) at the beginning of the lines:

max_execution_time = 300
memory_limit = 256M
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
log_errors = On
error_log = /var/log/php/error.log
max_input_vars = 2500
upload_max_filesize = 32M

21. To make sure you can upload file larger than 2MB within WordPress, edit this file:

nano /etc/nginx/nginx.conf

22. Add this in the http (or server or location) block:

# set client body size to 32M #
client_max_body_size 32M;

Save and exit.

23. Reload NGINX:

systemctl reload nginx

Hourra! You now have a new install of WordPress on your server, and it’s able to use permalinks, upload larger files and function with most premium theme and plugins.