Website Vidya
WordPressStep-by-Step Guide

How to Install WordPress on Ubuntu 18.04 LTE - LEMP Stack

This guide covers the step-by-step guide on how to Install WordPress on Ubuntu 18.04, 16.04, 14.04 LTE Server with LEMP Stack to help your website perform better and faster. WordPress is a popular, Dynamic and blog-focused content managemen...

RR
Website Vidya TeamLead Systems Educator
Published:
6 min read
How to Install WordPress on Ubuntu 18.04 LTE - LEMP Stack
AI Executive SummaryCORE CIS AI

6 min read

This guide covers the step-by-step guide on how to Install WordPress on Ubuntu 18.04, 16.04, 14.04 LTE Server with LEMP Stack to help your website perform better and faster. WordPress is a popular, Dynamic and blog-focused content managemen...

Key Highlights
  • Steps to Install WordPress on Ubuntu
Grounded in full engineering runbookCORE CIS Ai Engine

This guide covers the step-by-step guide on how to Install WordPress on Ubuntu 18.04, 16.04, 14.04 LTE Server with LEMP Stack to help your website perform better and faster.

WordPress is a popular, Dynamic and blog-focused content management system. WordPress is by far the most famous and most used content management system for websites. There are 74,652,825 websites are using WordPress as a Content Management System for their websites and it is increasing day by day.

Many of the bloggers and webmasters like me are moving to SSD Cloud hosting for faster and better performance of their websites. So I decided to bring this tutorial, that would help you to install WordPress on SSD cloud, Ubuntu Server. Before you proceed, I would highly recommend to read and implement the Getting started guide and then secure your server. Once you complete both these steps then you can move to this WordPress Installation guide.

Steps to Install WordPress on Ubuntu

Before you begin to make sure you have two things configured:

1. Hostname

Check your hostname by typing the following command:

hostname
hostname –f

The first command will output your hostname, while the second command will output the fully qualified domain name (FQDN).

2. MySQL Database

Once you ensure that these two things are configured on your server, proceed to the next step and install MySQL Server by running the following command:

sudo apt-get install mysql-server

During the installation process, you will be prompted to set a root password. It is recommended that you choose a strong password.

Now harden the MySQL Server by running the mysql_secure_installation script.

sudo mysql_secure_installation

Now, login into your MySQL as a root user using the following command:

mysql -u root -p

Now enter the root login credentials to login into MySQL.

Once you enter into MySQL, create a database for your WordPress based website using the following command:

create database database-name;

Now, grant user privileges for the newly-created database. Replace user and password with the username and password you wish to use:

grant all on database-name.* to 'user' identified by 'password';

Now exit the MySQL:

quit

3. Deploy PHP with FastCGI

We all know that WordPress is PHP based and in order to deploy PHP applications, we need to implement the “PHP-FastCGI”. This will allow NGINX to properly handle and serve PHP based web applications and websites.

For PHP5-FPM

apt-get install php5-cli php5-cgi php5-fpm

For PHP7.0-FPM

sudo apt-get install php7.0-cli php7.0-cgi php7.0-fpm

Once you are done deploying PHP5-FPM or PHP7.0-FPM, you need to move further and install the NGINX web server.

4. NGINX Server Setup

Install NGINX by typing:

sudo apt-get install nginx

Now create a new config file for your websites:

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com

Now you need to open the config file, in our case, it is example.com, and edit it.

sudo vim /etc/nginx/sites-available/example.com

Now you need to configure this file, and your file should look like this:

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/website1.com/public_html;
index index.php;
# Make site accessible from http://localhost/
server_name example.com www.example.com *.example.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

You can keep the exact copy of the above content as well. But do not forget to update the Website Directory and Server Name (server_name).

Once you’ve created and configured the file you can move on.

Next, we need to link this config file to the sites-enabled directory. For that you need to run the following command:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

Now, remove the default config file from the sites-enabled directory by typing:

sudo rm /etc/nginx/sites-enabled/default

Finally, restart the NGINX service

sudo service nginx restart

5. Changes Inside HOST file

Open the host file inside the etc directory and update your domain name inside the host file. It should look like something this:

hostname

6. Install WordPress

Create an src directory under your website’s directory and download the latest copy of WordPress. In this guide, I have chosen /var/www/exmaple.com/ as a home directory. So, create that directory if you do not have:

sudo mkdir /var/www/example.com/src/

Now, navigate inside the src directory.

cd /var/www/example.com/src/

Now set the owner of the new directory to be your web server’s user. In this instance, our web server is NGINX:

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

Now you need to download the latest version of WordPress and expand it:

sudo wget http://wordpress.org/latest.tar.gz
sudo -u www-data tar -xvf latest.tar.gz

Now you need to move latest.tar.gz by renaming it as WordPress, followed by the date to store a pristine backup of the source files:

sudo mv latest.tar.gz wordpress-`date "+%Y-%m-%d"`.tar.gz

Copy the WordPress files to your public_html folder, then remove the empty WordPress folder in the src directory:

sudo cp -R wordpress/* ../public_html/
sudo rm -rf wordpress/

7. Configure WordPress

Method 1:

Now, visit your domain in the browser and follow the configuration process by entering Database Name, User Name, and Password. Keep Database Host and Table Prefix to default localhost and wp_ respectively.

Submit the information, and you are good to go.

Method 2:

Navigate to your website directory /var/www/example.com/public_html/ and look for the wp-config-sample.php file and make a duplicate copy with the name wp-config.php inside the same directory.

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

Now edit the wp-config.php file using your favourite editor and enter the database information.

sudo vim wp-config.php

Once you enter the database details, exit the edit mode by pressing ESC and then press :wq!, hit enter to save and exit. Now when you visit your website by entering the domain name into the browser, you can see a recent default WordPress theme based website. You can change theme and pages entering into the admin panel.

You might face an issue while trying to update WordPress or install new themes or plugins. You will be asked to input your FTP information. Which sometimes feels very frustrating, especially if you are new to WordPress. To bypass this, you need to configure your wp-config.php file by adding the FS_METHOD:

/var/www/example.com/public_html/wp-config.php
/** Bypass FTP */
define('FS_METHOD', 'direct');

Once you are done, give WordPress permission to add and edit files in the public_html folder:

sudo chown -R www-data:www-data /var/www/example.com/public_html

Congratulations! Now, you have a successfully installed WordPress based website running.

Now you will be able to login into your new WordPress based website. Next, you can configure your website using a web-based interface.

For more help on how to install WordPress on Ubuntu, you can check the official documentation of Ubuntu as well.

Next Step: Improve search engine visibility and security of your website by installing Free SSL Certificate by Let's Encrypt.

I hope you will find this tutorial on how to install WordPress on Ubuntu useful.

If you face any difficulty throughout this process, put it in the comment section below. I will give my best to resolve it.

Written by

Website Vidya Team

Technology educator and researcher at Website Vidya.

Discussion

0
Share your thoughts, ask a question, or suggest a tip...
Write →

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

WordPress•

How to Create a Table of Contents in WordPress

How to create a table of contents in WordPress? Did you ever want to add a table of contents just like Wikipedia has on its website? If yes, I’m going to show you a way that you use to put a similar table of contents box on your blog or web...

RR
Rajesh Rai
Read More
WordPress•

How to Upload SVG to WordPress - 3 Easy Methods

Do you want to embed SVG in the WordPress website? Learn how to upload SVG to WordPress effortlessly with 3 simple methods. Enhance your website with captivating graphics. This how-to guide is for all levels. By default, the WordPress conte...

RR
Rajesh Rai
Read More