How to Install WordPress on Ubuntu 16.04 with Nginx, MariaDB, PHP7.2

This tutorial is going to show you how to install WordPress on Ubuntu 16.04 LTS with Nginx, MariaDB and PHP7.2. WordPress is the most popular CMS in the world. It is estimated that more than a quarter of websites today are powered by WordPress.

This tutorial assumes that you have already set up a Ubuntu 16.04 LTSwith Nginx, MariaDB and PHP7.2.
If not, please check out the following tutorial.


Step 1: Download WordPress

SSH into your Ubuntu 16.04 server and update existing software.

sudo apt update & sudo apt upgrade

Next, go to download page and download the zip archive. You can acquire the direct download link by right-clicking the download button and select copy link address.


Then at the command line prompt, type in wget followed by the direct download link to download WordPress to your Ubuntu 16.04 server.


Next, extract the zip archive using the command below.

sudo apt install unzip
sudo unzip
mv wordpress

A new directory named wordpress will be created in the current working directory. Now We move this directory and all its content to Nginx web root. Replace with you real domain name.

sudo mv wordpress/ /usr/share/nginx/<


Step 2: Create a Database and User for WordPress Site

Log into MariaDB shell as root with the following command.

mysql -u root -p

Once you are logged in, create a database for WordPress using the following command. I named it wordpress, but you can use whatever name you like such as you site name. (Don’t leave out the semicolon.)
create database wordpress;

Then enter the command below to create a database user for WordPress. This command also grant all privileges of WordPress database to the user. Replace wpuser and your-password with your preferred username and password.

grant all privileges on wordpress.* to wpuser@localhost identified by 'your-password';

Flush the privileges table for the changes to take effect and then get out of MariaDB shell.

flush privileges;


Step 3: Configure WordPress

Go to your WordPress directory.

cd /usr/share/nginx/

Copy the sample configuration file and rename it to wp-config.php.

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

Now edit the new config file.

sudo nano wp-config.php

Find the following lines and replace the red texts with the database name, username and password you created in the previous step.

/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

Save and close the file. We also need to set the Nginx user www-data as the owner of the WordPress site directory by using the following command.

sudo chown www-data:www-data /usr/share/nginx/ -R


Step 4: Create a Nginx Server Block for WordPress

We will create the server block file in /etc/nginx/conf.d/ directory. The file name must end with .conf.

sudo nano /etc/nginx/conf.d/

Put the following texts into the file. Replace the red texts with your own domain name. Don’t forget to create A records for your domain name.

server {
  listen 80;
  root /usr/share/nginx/;
  index index.php index.html index.htm index.nginx-debian.html;

  location / {
    try_files $uri $uri/ /index.php;

  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;

  location = /50x.html {
    root /usr/share/nginx/html;

  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.1-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;

  location ~ /\.ht {
    deny all;

Save and close the file. Then test Nginx configurations.

sudo nginx -t

If the test is successful, reload Nginx.

sudo systemctl reload nginx


The Final Step: Run WordPress Install Wizard

Enter your domain name in browser address bar. You shall see the WordPress installation wizard. Select a language.


If the installation wizard isn’t displayed,  you probably need to install some PHP7 extensions.

sudo apt install php7.1-mbstring php7.1-xml php7.1-mysql php7.1-common php7.1-gd php7.1-json php7.1-cli php7.1-curl

Then reload PHP-FPM and Nginx. The wizard should now be displayed.

sudo systemctl reload php7.2-fpm
sudo systemctl reload Nginx

And now your new WordPress site is installed.


I hope this tutorial helped you install WordPress on Ubuntu 16.04 with Nginx, MariaDB and PHP7.2 (AWS EC2).



I am a Freelance Web Developer and WordPress Expert based in London with a wealth of website development and support experience. I am great at problem solving and developing quick solutions.

    Website Design Oakville

    July 24 2018 / 6:09 pm

    Wonderful resourceful information. I actually like what I’ve acquired here. You make your blog posts pleasurable and easy to comprehend. I can not wait to read more from you.


Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.


    Fill in the form below to make an enquiry or find my contact details on my contact page.

  • This form collects your name and email address so that I can respond to the enquiry(ies) that you submit via this website. Please check my privacy policy for the full story on how I use, protect and manage your submitted data.