WordPress is the most popular CMS (content management system), which allows you to create beautiful websites and blogs as easily as ABC. It allows you to manage pages and posts in the web front-end, and over 39.5% of all the websites on the Internet are using WordPress.
In this post, I’ll guide you on how to set up a WordPress on a LEMP stack (Linux, Nginx, MySQL, and PHP) on an Ubuntu 18.04 server.
Prerequisites:
- Ensure that you have access to an Ubuntu 18.04 server.
- A domain name pointing to your server’s IP address.
Step 1: Installing Nginx Web Server
In this post, we are going to use the Nginx server. Let’s install Nginx by using :
Type sudo nginx -v
to check the version of Nginx installed on your server.
Let’s configure the firewall now. If you don’t want to use a firewall, you can skip below and jump to Step 2.
Enable the firewall by typing :
You can check available profiles under the firewall by using:
The output will be:
Note: Execute the command below for the firewall to allow ssh connections, so that we can log in back using ssh.
Let’s set up the firewall to allow connections to Nginx. Enable this by typing:
Note: If you don’t want to configure SSL to your server, then, you can just allow only ‘Nginx HTTP’. A tutorial on how to configure SSL will be available below in this blog.
You can verify the change by running:
This command’s output will show that HTTP and HTTPS traffic(Nginx Full) is allowed:
With the new firewall rule added, you can test if the server is running by accessing your server’s domain name in your web browser.

If you see the above page, you have successfully installed Nginx on your server.
Step 2: Installing MySQL
Let’s install MySQL to store and manage the data on our site.
Install MySQL by typing:
MySQL is now installed.
To secure the installation, MySQL comes with a script for modifying some insecure defaults. Initiate the script by typing:
This script will ask if you want to configure the VALIDATE PASSWORD
PLUGIN.
If you don’t need to type No and proceed. If you want to configure validate password plugin, follow the below steps. After running the above command you will see this.
If you’ve enabled validation, the script will also ask you to select a level of password validation.
Note: Whatever you select(say it low, medium, or strong) MySQL won’t allow password which doesn’t match their password validation criteria.
Next, you’ll be asked to submit and confirm a root password:
For the rest of the questions, you should press Y and hit the ENTER key at each prompt. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MySQL immediately respects the changes we have made.
By default, MySQL server authenticates the root users via auth_socket
rather than by password. If we allow auth_socket
authentication, it will cause some problems in configuring external software like PHPMyAdmin.
So to make MySQL user to authenticate using passwords, follow these steps:
Next, to check the authentication method of your MySQL user accounts use the following command:
In this example, you can see that the root user authenticates using the auth_socket
plugin. To configure the root account to authenticate with a password, run the following command. Be sure to change your password to a strong password :
Check the authentication methods employed by each of your users again to confirm that the root no longer authenticates using the auth_socket
plugin:
You can see in this example output that the root user is now authenticated using a password. Once you confirm this on your own server, you can exit the MySQL shell:
Step 3: Installing PHP
We need to install php-fpm, which stands for “fast CGI process manager” to tell Nginx to pass PHP requests to this software for processing and additionally php-mysql package to communicate with DB.
And that’s it, we have installed all the components of the LEMP stack.
Step 4: Configure the server to use PHP
Go to /etc/nginx/sites-available
directory, create a new or open your server configuration file.
Note: You can use the default, but here I am using the server configuration file name mydomain.com
Add the following to the server block file /etc/nginx/sites-available/mydomain.com
Save and exit once done. Link your server configuration file to the sites-enabled and unlink default
from sites-enabled.
Test your new configuration file by typing:
If any errors are reported, go back and recheck your file before continuing. If there are no errors, reload Nginx to make the necessary changes:
Step 5: Installing WordPress
Let’s create a new MySQL Database and User for WordPress.
Login using root:
For auth_socket
plugin:
For mysql_native_password
plugin, run the below command, and enter the password:
Let’s create a new database for WordPress.
Note: password should match your mysql’s password validator criteria.
Create a new user and give access for new user to WordPress database:
Now, let’s install required packages for WordPress;
Restart php-fpm for changes to reflect on the server
Now, let’s configure our server configuration file.
Add these lines to your server configuration file /etc/nginx/sites-available/mydomain.com
Note: In the upcoming steps, we are going to install WordPress inside /var/www/wordpress. You can install anywhere, but make sure you have configured root in the server configuration file to point to the installed path.
Here in root, I am using /var/www/wordpress.
Now add these lines inside /etc/nginx/sites-available/mydomain.com
:
When you are finished, save and close the file. Now, we can check our configuration for syntax errors by typing:
Next, let us download and set up WordPress. Follow the steps:
To extract the compressed file:
Copy wp-config-sample.php file to we-config.php:
Move the directory to the root (or your desired location). Make sure you mentioned your project dir under root in your server configuration file.
Now, let’s set up the WordPress configuration file.
For this, to get secret values from WordPress Secret Key Generator type:
You will get unique values. Copy that and open the WordPress configuration file:
add your copied secret keys to the relevant sections.
Configure your database:
Save and close the file when done. Now go to http://your-domain.com . You can see this.

Now select your language and complete the installation process. After successful completion, you will see the dashboard.
Step 6: Configuring SSL (HTTP to HTTPS)
Let’s install certbot
Press ENTER to accept.
Install Certbot’s Nginx package
Now make sure you have allowed the firewall to accept Nginx HTTPS. If not please enable Nginx HTTPS.
You can check the configurations by:
If you made any changes, don’t forget to reload ufw by
To obtain an SSL certificate:
You have to enter your email address and agree to their terms of service. After that, it starts its verification. Once successful verification, certbot will ask to configure HTTPS settings. Select which you need and the configuration will be updated with a successful message like this
Now try loading as https://your-domain.com in your web browser, It should be indicated that the site is secured.
To test the renewal process, you can do a run with certbot:
Congratulations! You have successfully completed installing WordPress in your server secured with SSL.