How to Install WordPress with LEMP(Linux-Nginx-Mysql-PHP) on Ubuntu 18.04

By: Sunil Kumar |  In: WordPress  |  Last Updated: 2018/10/13

How to Install WordPress with LEMP(Linux-Nginx-Mysql-PHP) on Ubuntu 18.04

WordPress is the most popular CMS available on the internet. and when you use Nginx as the back of your WordPress site it makes it more powerful.
In this guide, we will be installing WordPress with LEMP stack(Linux-Nginx-Mysql-PHP) and all its dependencies you need to run WordPress and configuring WordPress for the first time use.

Installing PHP

PHP 7.2 is the latest and default version in Ubuntu 18.04 and recommended for WordPress. To install the latest version of PHP and all the extension on your Ubuntu system you can use this command

sudo apt update
sudo apt install php7.2-fpm php7.2-mysql php7.2-json php7.2-opcache php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl

Here we are installing PHP-FPM instead of PHP-CLI because we will be using Nginx server instead of the Apache web server.

Installing Mysql and creating database and user for WordPress

WordPress uses Mysql database to store all of its information and the data. So before configuring, we must have Mysql database service installed and enabled on our server.
To install Mysql server use

sudo apt-get install mysql-server

after installing We have to make a database and a user for WordPress to use. To create a user login to your MySQL root account using

mysql -u root -p

It will prompt for the root password you created while installing the Mysql server.
after logging in to your MySQL server create a database for WordPress. You should be creating a different database for each of your project.

mysql> create database mywordpress_site DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Now we will be creating a user for WordPress

mysql> GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'MY_PASSWORD';

We created a user wordpressuser and granted all the permission to that user.
Now we need to flush all the privileges to make all the changes effective.


you can log in to this MySQL user using

mysql -u wordpressuser -p

Now exit from the MySQL server using

mysql > EXIT;

after creating the database and user our your project we are ready to move forward.

Installing and Configuring Nginx

if you don’t have Nginx installed on your server You can install it by using

sudo apt install nginx

or you can follow this guide to install Nginx on your server.

A step by Step Guide to Install Nginx server on Ubuntu

After installing Nginx we need to make some minor configuration adjustment to run WordPress site on your server.
create the configuration file
You have to create a Nginx block file on your server which is going to respond when you hit your domain from the browser.
Also, you can make a copy of the sample block file

sudo cp /etc/nginx/sites-enabled/default /etc/nginx/sites-available/mywordpress-site

now open the file and make the changes

sudo nano /etc/nginx/sites-available/mywordpress-site
server {
   listen 80;
   listen [::]:80;
   root /var/www/html;
   index index.php index.html index.htm index.nginx-debian.html;
   location / {
      try_files $uri $uri/ =404;
   location ~ \.php$ {
      include snippets/fastcgi-php.conf;
      fastcgi_pass unix:/run/php/php7.2-fpm.sock;
   location ~ /\.ht {
      deny all;

Now check the configuration file for any syntax error using-

sudo nginx -t

if no error found, reload the Nginx to make the configuration effective

sudo service nginx reload

Download and setup WordPress

Now as we have configured everything it is time to Download the WordPress. You can Download the latest version of the WordPress using this link
or using terminal

cd /var/www/
mkdir projects
cd projects
curl -LO

Now extract the downloaded file

tar xzvf latest.tar.gz

now rename the directory to your project-name to identify the project(mywordpress-site here).

mv latest mywordpress-site

Now we need to copy the sample config file to actual config file

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

Now we need to change the group and user of that directory to www-data as Nginx runs as that user and group. By doing this Nginx will be able to read the files of that project

sudo chown -R www-data:www-data /var/www/projects/mywordpress-site

So now we have the WordPress project downloaded and placed into the right location.
Now we need to make some changes to WordPress configuration
The first thing we need to do is produce the secret key and paste them into config.php file. Don’t worry, you don’t need to come up with a unique key by yourself. WordPress provides a utility to produce unique keys
To grab secure values from the WordPress secret key generator, type:

curl -s

and it will output something like this

define('AUTH_KEY', 'jkw4y59jnfjsdf(0dfj)-9v#mScM+#8!V8G7=z');
define('SECURE_AUTH_KEY', 'Yi8fyahHODu((DHS))nnL$5Z@6#Z_hzaD@VR');
define('LOGGED_IN_KEY', 'nk8xzWw#N_!wpKW^Q86VqCMVS72CpYTEV@3?');
define('NONCE_KEY', '?Gz$Dyg&2Sk77uA?6Ua&5bz+&E_Nh=8PT-Lj');
define('AUTH_SALT', 'v3rVcwaW-G#uP6hv^7e92^6r2gQWv_uscamw');
define('SECURE_AUTH_SALT', 'p32*p,]z%LZ+pAu:VY%L8$jr?A5j?xaR7Cuy');
define('LOGGED_IN_SALT', 'w2*Cu4b2n+=br-!N-8_95M@dvth4Bn_y2Mb=');
define('NONCE_SALT', 's!@%dx44M+2NLx5jWnmkC?EyPBS+K2+Ak2J@');

NOTE:- this is a sample to show you the format of the keys. Don’t use these Keys in your project. produce new keys and the use them.
now open the config.php file

sudo nano /var/www/wordpress/wp-config.php

and look for the following code and replace that with the latest generated keys

define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');

Now we need to make the database connection settings so WordPress can connect to the database
look for these lines of code and change accordingly

define('DB_NAME', 'mywordpress_site');
/** MySQL database username */
define('DB_USER', 'wordpressuser');
/** MySQL database password */
define('DB_PASSWORD', 'my_password');

Compile the Installation through the Web interface

Now server configuration part is complete and we are at the final stage of completing WordPress installation.
To complete the setup, open your browser and navigate to your domain or server IP


for localhost or http://localhost

You will be landed to the setup page. You set up your username and password to login to your wordress dashboard, your site name(you can change later), your email address etc.
wordpress login nformations
fill all the information and click on the Install WordPress button at the bottom.
wordpress success message
after successful installation, you will be redirected to the login screen and asked to provide your login username and password you entered in the previous setup page.
wordpress login screen
Once you login you will be landed to the WordPress admin dashboard where you can customize and make other change to your WordPress site.
form now, next time you hit your domain name or server ip you will be landing to your WordPress site.
To access your WordPress domain use



Now are have setup WordPress on your ubuntu 18.04 system with Nginx server and MySQL database system. If you are using WordPress for the first time I suggest you go around all the settings, explore the interface thoroughly before start making any changes.


  • Leave a Comment

    Your email address will not be published.


    Sunil Kumar

    I am the owner of acmeextension. I am a passionate writter and reader. I like writting technical stuff and simplifying complex stuff.
    Know More

    Join more than 10,000 others Web Developers