How to install wordpress on LEMP stack

How to install wordpress on LEMP stack: In this article I will describe you step by step how to install wordpress on Linux Ubuntu 18.04 with NGINX MySQL and php.

How to install wordpress on LEMP stack?

The contents of the article

  • How to install wordpress on LEMP stack?
  • Prerequisites for the tutorial
  • MySQL configuration
  • Setting up php
  • Configuring nginx
  • WordPress download
  • WordPress configuration
  • Conclusions

Do you want to know how to install wordpress on LEMP stack ? Have you recently activated a VPS with nginx and want to know how to best configure wordpress ?

So follow me, in this article I will tell you step by step how to install wordpress on lemp stack with Ubuntu 18.04, NGINX, MySQL and php.

In this way you will have the possibility to really turbo your blog , using the stack of the moment: LEMP (Linux, nginx, MySQL and php)

Do you want to know if the  performance  of your wordpress blog could be improved? Are you interested in how to  migrate  your blog from  Shared Hosting  to  dedicated VPS ? Would you like to install wordpress with nginx  for your website?


Prerequisites for the tutorial

As an indispensable prerequisite you must have a dedicated VPS with pre-installed the LEMP stack or Linux (in this tutorial I use Ubuntu 18.04 ), nginx, MySQL and php

If you don’t know what the LEMP stack is or you want to know how to install it on a dedicated VPS then I recommend this article of mine:


YOU MAY BE INTERESTED IN …How to install LEMP stack on VPS (Linux NGINX MySQL php)

Also you must have a user (possibly not root) with sudo access rights

MySQL configuration

First you need to configure MySQL to manage the database that will host the data of your wordpress blog. Setup involves creating the database and user needed for your blog.

Then access MySQL from the command line (shell ssh) using the command:

$ sudo mysql -u root -p

Enter the password for root and access to the mysql console.

First check that everything is working correctly, so run the following command:

mysql> show databases;

You should have on the console the list of databases on your installation, then proceed to create the new database, which you can call whatever you want. For this tutorial I will use the wordpress name but you can choose any name.

mysql> CREATE DATABASE wordpress ;

With this command you have just created the wordpress database , now proceed with the creation of a new user and related permissions . Also for the user to create you can use any name, I will use wpuser .

If you have installed MySQL on the same machine where nginx is installed then you will need to use a user like:

wpuser @ localhost

otherwise, if you have installed the database on a different machine , the user you need to create will be like:

wpuser @ [ip_address_db_server]

For this tutorial I will use the first configuration , but consider that it is good practice not to install the database on the same machine where you install the application server or the reference webserver (in this case php and nginx).

Then proceed with the creation of the user with the command:

mysql> CREATE USER ‘ wpuser ‘ @ ‘localhost’ IDENTIFIED BY ‘ UnaPasswordForte ‘;

and with the definition of the grant (permissions) on the database

mysql> GRANT ALL PRIVILEGES ON ` wordpress` . * TO ` wpuser` @ `localhost`;

Finish the operation with the flush command to persist the changes


Check privileges with the command:

mysql> SHOW GRANTS FOR ‘ wpuser ‘ @ ‘localhost’;

Exit the mysql console with the command

mysql> exit;

Setting up php

Now that you have created and configured the database and the user who will have access to the database, you can proceed with the specific php configuration for wordpress.

The php extensions for wordpress you can install them with the command:

$ sudo apt update$ sudo apt install php-curl php-gd php-intl $ sudo apt install php-mbstring php-soap php-xml php-xmlrpc php-zip

After the installation is complete you will need to restart php-fpm with the command

$ sudo systemctl restart php7.2-fpm

Now all the extensions necessary for the correct running of wordpress are installed on your Linux VPS.

Configuring nginx

Once the php configuration is complete you can proceed with the configuration of nginx to run your wordpress blog.

In this tutorial I will use the following directories for the nginx configuration file and the wwwroot that is the home directory of the webserver in which to install wordpress:

/ etc / nginx / sites-available / wordpress => nginx configuration file

/ var / wwwroot / html / => wordpress home directory

Then start by creating the nginx configuration file for the wordpress blog, starting from the default file already present in the directory, with the command:

$ cd / etc / nginx / sites-available /$ sudo cp default wordpress

disable the default configuration

$ sudo unlink / etc / nginx / sites-enabled / default

Proceed with the configuration of the wordpress file you just created

$ sudo nano / etc / nginx / sites-available / wordpress

search for the row that contains the index entry and change it as follows:

index index.php index.html index.htm index.nginx-debian.html;

look for the line containing the server_name entry and add your domain name:


Look for the location section and change it inside as follows:

location / {     try_files $ uri $ uri / /index.php$is_args$args ;}

At this point the main changes are finished and you should be able to verify the correctness of the nginx files with the command:

$ sudo nginx -t

If everything is ok then restart nginx with the command:

$ sudo systemctl reload nginx

WordPress download

How to install wordpress on lemp stack: You’re almost there, your server is ready to download and configure wordpress, so proceed as follows:

$ cd / tmp$ curl -LO

Extract the archive

$ tar xzvf latest.tar.gz

Create the wordpress configuration file as a copy of the “sample” file

$ cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

Copy the files to the nginx wwwroot

$ sudo cp -a / tmp / wordpress /. / var / www / html

Change owner of files and directories to www-data

$ sudo chown -R www-data: www-data / var / www / html

Set the correct permissions for wordpress files

$ cd / var / www / html /$ sudo find. -type f -exec chmod 664 {} +$ sudo find. -type d -exec chmod 775 {} +$ sudo chmod 660 wp-config.php

You are there, the download and related installation of wordpress is finished, now you can proceed with the final configuration .

WordPress configuration

Now that you have copied the wordpress files to the nginx home directory you can proceed with the final configuration to make the blog live.

First we generate new security keys by running the following command from the shell:

curl -s

You will get output similar to this

define (‘AUTH_KEY’, ‘aaaaaaaaa’);define (‘SECURE_AUTH_KEY’, ‘bbbbbbb’);define (‘LOGGED_IN_KEY’, ‘cccccccc);define (‘NONCE_KEY’, ‘dddddddd’);define (‘AUTH_SALT’, ‘eeeeeeee’);define (‘SECURE_AUTH_SALT’, ‘fffffffff’);define (‘LOGGED_IN_SALT’, ‘ggggggg’);define (‘NONCE_SALT’, ‘hhhhhhhh’);

Setting: Do not use the values ​​I entered , you must use the values ​​you will get by running the command from the shell

Now edit the wordpress configuration file with the command

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

And copy the newly generated values ​​into the related section. Now you can go to configure the data relating to the connection with the MySQL database, then enter the database values , username and password you created just before:

define (‘DB_NAME’, ‘ wordpress ‘); / ** MySQL database username * /define (‘DB_USER’, ‘ wpuser ‘); / ** MySQL database password * /define (‘DB_PASSWORD’, ‘ password ‘);

Now you can launch the final setup by simply typing your website url into the browser

http: // your_domain_or_your_IP

Then select the Italian language and enter a username,  a password and a reference email for your administrative account . The game is done!

You are now ready to access the administrative panel of your newborn wordpress blog installed on the LEMP stack .


In this article I have told you and described step by step how to install wordpress on LEMP stack with Ubuntu 18.04, NGINX, MySQL and php. Remember that for the correct execution of the tutorial it is necessary to have the stack already installed , if you don’t know how to do it I’ll tell you everything in this guide .

Did you like the tutorial? Do you want to share your experiences or concerns regarding VPS and LEMP stacks with me


by Abdullah Sam
I’m a teacher, researcher and writer. I write about study subjects to improve the learning of college and university students. I write top Quality study notes Mostly, Tech, Games, Education, And Solutions/Tips and Tricks. I am a person who helps students to acquire knowledge, competence or virtue.

Leave a Comment