WordPress is one of the most common and popular Content Management System (CMS) that acquires a large share in market in compare to other CMS options available in market. With the help of this open source CMS, users can develop any type of website whether it be for an organization, blog, small business, and so on. It offers a large number of free and premium plugins as well as themes to cherish website’s beauty and functions.
Also, the developers can develop a custom theme and plugins according to their needs, and all from scratch that allow them to embed any functions to their WordPress website, So, in this article, it’s discussed about how the installation of WordPress can be done using LEMP/Nginx as a Web Server on Ubuntu 18.04 (Nginx, PHP, MySQL).
Prerequisites
Before you start with the guidelines, it’s necessary to access an Ubuntu 18.04 server, also need to do some tasks as well, which are as follows:
- Open SSH session to your Ubuntu 18.04 server using root or any ‘sudo’ enabled user.
- A domain/subdomain pointing to the WordPress installation.
- Domain/subdomain DNS A-record locating to server’s IP address. (To get the IP, Check the control panel of Ubuntu server).
Note: In this tutorial, we are using abc.com as domain name for an instance. In your case, do make sure to replace the abc.com with your own domain name, where you see.
Step 1: Update Ubuntu 18.04
Before you start to install Nginx/Lemp, it’s suggested to update your server with latest updates. Here are the commands to do that.
sudo apt-get update sudo apt-get upgrade
With the use of first command, it will update the list of available packages and their versions. While, the second command will install the newer version updates to all packages which are installed on Ubuntu server.
Step 2: Install WordPress with Nginx on Ubuntu 18.04
Once the server packages are up-to-date, you can follow further steps to install WordPress with Nginx using MySQL, and PHP.
Step 2.1: Install Nginx
In Ubuntu, Nginx is available in default repositories and can be installed easily with the the command below.
sudo apt-get install nginx
After the Nginx is installed, it’s suggested to stop, start and enable Nginx service to assure its initialization after ever server boots. Below are the commands to run
sudo systemctl stop nginx.service sudo systemctl start nginx.service sudo systemctl enable nginx.service
Step 2.2: Install MySQL
Since wordpress needs a Database to work with, we suggest to use MySQL. To install it, run the commands.
sudo apt-get install mysql-server
While the installation is done, you will be asked to input your password for MySQL. Do make sure to input a strong password. And hit enter to re-enter the password again.
With above executed commands, MySQL is installed with default settings, but you need to make it more secure with further commands below.
sudo mysql_secure_installation
After running above command, you will be asked to answer various questions to assure your security. We suggest you to do as mentioned below.
- Feed the current password for root (Press enter for none), Press Enter key.
- Set Root password? [Y/m]: Y
- New Password: Enter your password here
- Re-enter new password: Repeat your password once again
- Remove anonymous users? [Y/n]: Y
- Disallow root login remotely? [Y/n]: Y
- Remove test database and access to it? [Y/n]: Y
- Reload privilege tables now? [Y/n]: Y
Once done, restart MySQL server’s
sudo systemctl restart mysql.service
Step 2.3: Install PHP 7.1 and Essential WordPress Modules
WordPress CMS requires PHP. In order to install PHP 7.1 it’s required to add a third party repository. To do so, run the commands below to add the repository and upgrade to PHP 7.1
sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php
The above command will add repository to Ubuntu server, next is to upgrade to PHP 7.1
sudo apt update
Now, run the commands mentioned to install PHP 7.1 FPM and other related modules.
sudo apt install php7.1-fpm php7.1-common php7.1-mbstring php7.1-xmlrpc php7.1-soap php7.1-gd php7.1-xml php7.1-intl php7.1-mysql php7.1-cli php7.1-mcrypt php7.1-zip php7.1-curl
Now, run the commands below to open PHP-FPM default file.
sudo nano /etc/php/7.1/fpm/php.ini
In the default file, do some modifications in the following lines and save the file. We suggest you to fee below settings to make WordPress easily in server.
file_uploads = On allow_url_fopen = On memory_limit = 256M upload_max_filesize = 100M cgi.fix_pathinfo=0 max_execution_time = 360 date.timezone = America/Chicago
Step 2.4: Create Database for WordPress
In order to create database for wordpress, you first need to login to MySQL, below is the command to run. When asked, enter your root password.
sudo mysql -u root -p
Now, create a databse with below command. We have created a database named “servonode” in the example below.
CREATE DATABASE servonode;
Create a database user for the database with name “servonodeuser” with a new password
CREATE USER 'servonodeuser'@'localhost' IDENTIFIED BY 'new_password_here';
Next is to grant full access to created user over created database.
GRANT ALL ON servonode.* TO 'servonodeuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
Lastly, save the changes and quit MySQL.
FLUSH PRIVILEGES; EXIT;
Step 2.5: Download WordPress Latest Release and Save The Files Under A Directory
In order to download WordPress latest release, visit the WordPress site and download the latest version. Then extract the downloaded file and move it into a new WordPress root directory (servonode is taken here as example).
cd /tmp && wget https://wordpress.org/latest.tar.gz tar -zxvf latest.tar.gz sudo mv wordpress /var/www/servonode
Set correct permissions to assigned root directory for wordpress to work properly.
sudo chown -R www-data:www-data /var/www/servonode/ sudo chmod -R 755 /var/www/servonode/
Step 2.6: Nginx HTTP Server Configuration
You need now to configure Nginx site configuration file for WordPress. This file is essential to control how users can access your wordpress content, just run the commands below to create a new WordPress configuration file called “servonode.conf”
sudo nano /etc/nginx/sites-available/servonode.conf
Just copy the code content below and paste it into the configuration file and save it. Do not forget to replace the highlighted value with your own domain and directory root location.
server { listen 80; listen [::]:80; root /var/www/servonode; index index.php index.html index.htm; server_name example.com www.example.com; client_max_body_size 100M; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
Save the modified file and exit.
How To Secure Your Site With Free SSL With Nginx On Ubuntu Server
Step 2.7: Enable the WordPress Configuration file and Rewrite Module
After configuration of virtual host, it requires to be enabled for which run the commands below:
sudo ln -s /etc/nginx/sites-available/servonode.conf /etc/nginx/sites-enabled/
Step 2.8: Restart Nginx Service
Once the configuration file is configured and enabled, it’s suggested to restart Nginx with the commands below.
sudo systemctl restart nginx.service or sudo service nginx restart
Step 2.9: Configure Wp-config.php
Here’s the command to rename wp-config-sample.php to wp-config.php and feed the data we have created above to configure WordPress configuration file.
sudo mv /var/www/servonode/wp-config-sample.php /var/www/servonode/wp-config.php
Now, execute the following command to open and edit WordPress configuration file.
sudo nano /var/www/servonode/wp-config.php
Once the file is opened, feed the data like database name, database user name, and password as highlighted in the section below.
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'servonode'); /** MySQL database username */ define('DB_USER', 'servonodesuser'); /** MySQL database password */ define('DB_PASSWORD', 'user_password_here'); /** MySQL hostname */ define('DB_HOST', 'localhost'); /** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8'); /** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', '');
Now, just save the file, and open your domain on the browser to launch WordPress installation wizard. You can see the WordPress wizard as shown below. Be careful to choose your preferred option as asked in installation procedure.
http://example.com or http://www.example.com (Open any of the protocol according to your need, whether to use www or non www)
in the next step, enter your website’s name, admin user and a password for it. Finally, click on Install WordPress button.
This should install WordPress on your selected domain, just login to your website now and you will see the dashboard as shown below.
That’s all, you have installed WordPress on Ubuntu server 18.04 now.

Nishant Verma is a senior web developer who love to share his knowledge about Linux, SysAdmin, and more other web handlers. Currently, he loves to write as content contributor for ServoNode.