How To Install Wordpress 5 On Lamp Stack Ubuntu 18 04

Getting Started

Wordpress is the most popular (CMS) Content Management System and free to use developed on PHP and Mysql.

Before you start, Make sure PHP, Mysql, and Apache2 are installed. If not you can follow the below link to install & configure LAMP Stack.

Follow this link to install LAMP Stack (PHP, Mysql, Apache2) 

Step 1. Configure Mysql

First, we'll create a new database for WordPress. To do so, Enter the following command to login as an administrator

 mysql -u root -p

Enter your root password and press enter. After login, you'll see the following screen.

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 5.7.25-0ubuntu0.18.04 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


Create a new database for WordPress

Enter the following command to create a new database.

create database blog;

Here I have created a database named blog. you can choose your own database name.

Create a new MYSQL User for WordPress

Enter the following command to create a new user.

create user 'wordpress'@'localhost';

Grant privilege to access the database for wordpress.

Enter the following command to grant permission to the new user.

GRANT ALL PRIVILEGES ON blog.* To 'wordpress'@'localhost' IDENTIFIED BY 'password';

blog.* means we are giving all tables access.


Testing WordPress user login.

Enter the following command to login msyql with WordPress user and press enter.

mysql -u wordpress -p

Next, Enter the following command to display the database.

mysql> show databases;
| Database           |
| blog               |

Step 2. Download and install WordPress

Wordpress can be download by two methods

1. Download from terminal

desert:html$ wget
--2019-04-13 15:24:54--
Resolving ( 
Connecting to ( connected.
HTTP request sent, awaiting response... 200 OK
Length: 11525128 (11M) [application/zip]
Saving to: ‘’               38%[============>                       ]   4.21M  1.78MB/s               ^

Next Extract the file using unzip. Note: You can install unzip with this command sudo apt install uzip


This will extract the zip file with the name wordpress. if you want to change the directory name you can enter the following command.

mv wordpress your-directory-name

I'll keep the same name as wordpress.

2. Download from browser

To download from the browser follow this link. once download, unzip the downloaded file and since we are working on /var/www/html move the extracted directory here.


Step 3. Setting up Virtual Host.

Copy virtual host file

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/wordpress.conf

Edit and set up the virtual host. You can open with any code editor. I'll open with vim editor.

sudo vi /etc/apache2/sites-available/wordpress.conf

Final configuration will look like this

<VirtualHost *:80>
        ServerName wordpress.local
        ServerAlias www.wordpress.local
        DocumentRoot /var/www/html/wordpress

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

Next, Add the virtual hosts

sudo a2ensite wordpress.conf


Enabling site example1.local
To activate the new configuration, you need to run:
  service apache2 reload

Now restart the server.

sudo service apache2 restart

 Next, change the folder permission

sudo chmod -R 777 wordpress

Note: It is not good practice to give 777 permission on the server. 

Step 4. Configure wordpress.

Now the virtual host is done.

Open wordpress.local 

wordpress installation screen

Click let's go button and enter the database detail

wordpress database detail

When you are done click submit. 

wordpress run the installation

Click run the installation.

enter website and wordpress user detail

Enter the site and login detail and we are done.

wordpress login screen