[Working] How to install WordPress on Ubuntu 20.04 Linux | Azure VM

Install WordPress on Ubuntu

In this blog, we are going to install WordPress on Ubuntu Linux Apache server running on Azure Virtual Machine.

Here is how we are going to do this:

  1. Create an Ubuntu Virtual Machine
  2. Connect to Ubuntu Server using SSH
  3. Install Apache2 HTTP server
  4. MySQL Installation and Configuration
  5. Install PHP and Related Modules
  6. Create the WordPress Database
  7. Download and Install WordPress

Introduction

WordPress is one of the world’s most popular web publishing platforms for building blogs and websites. From blogging to e-commerce to business and portfolio websites, WordPress is a versatile CMS. Designed with usability and flexibility in mind, WordPress is a great solution for both large and small websites.

There are different ways of hosting a WordPress site on Microsoft Azure. In this blog, we are going to install WordPress in Ubuntu 20.04 server using LAMP stack. This guide will also work on Ubuntu Server 18.04 LTS.

Install WordPress website on Azure using Bitnami Stack

Step 1: Create an Ubuntu Virtual Machine

First login to your Azure Portal and Create a Virtual Machine.

We can just click on Virtual Machine or search for Virtual Machine on Top Search Bar and click on Create.

After that, fill out some basic information. Choose your Subscription and resource group. Create a new resource group if you don’t have any. Then your Virtual Machine name and Region.

For Image, we will choose Ubuntu Server 20.04 LTS – Gen 1 and choose the size as per the requirement.

how to install wordpress in ubuntu linux using lamp stack in azure vm

Under Administrator account, select SSH public key.

In Username type the username you want.

For SSH public key source, leave it default, and then type the key name for the Key pair name.

Under the Public inbound ports, choose Allow selected ports and then select SSH (22) and HTTP (80) from the drop-down.

How to install WordPress on Ubuntu 20.04 Linux | Azure VM

Leaving everything else as defaults, click on Review + create. If it is still asking for some details, fill that and hit Create.

A new popup will show up and select Download private key and create resource. The key file will be downloaded as thekeyname.pem.

Once it is deployed, Go to the resource and note the Public IP address.

Microsoft Docs: Create a Linux virtual machine in the Azure portal

Step 2: Connect to Ubuntu Server using SSH

Create SSH connection with VM

Once the resource is deployed, click on Connect and select SSH.

How to install WordPress on Ubuntu 20.04 Linux Azure VM

There we get the instructions for connection.

Open the client of your choice. I am on my Windows machine at the time of creating this tutorial and using Git Bash.

Go to the path where you had downloaded the key file.

We need to ensure we have read-only access to the private key.

chmod 400 thekeyname.pem

Run the command to connect to the VM.

“ssh -i <private key path> azureusername@thePublicIPAddress”

For example, in my case:

ssh -i thekeyname.pem username@52.183.89.27

Enter ‘yes’ and we should now be connected to our Ubuntu Server.

Microsoft Docs: Connect to a Virtual Machine

Step 3: Install Apache2 HTTP Server

We are using Apache2 HTTP server, and to install it, run the following command:

sudo apt update

sudo apt install apache2

Enter the following command to ensure that Apache2 Service starts automatically after a reboot.

sudo systemctl stop apache2.service

sudo systemctl start apache2.service

sudo systemctl enable apache2.service

Now, its been installed, lets check if the web server is working or not.

Go to the browser and visit the public IP address. In my case it is: 52.183.89.27

How to install WordPress on Ubuntu 20.04 Linux

If there is a page like above, mission passed.

Step 4: Install and Configure MySQL

Install MySQL in Ubuntu 20.04

WordPress requires a database to store its contents. We are using MySQL for it and to install the MySQL database server, run the following command:

sudo apt install mysql-server

Enter the following command to ensure that MySQL Service starts automatically after a reboot.

sudo systemctl stop mysql.service

sudo systemctl start mysql.service

sudo systemctl enable mysql.service

MySQL Configuration

Now, to perform a secure install for MySQL, lets configure the security options by executing the following command:

sudo mysql_secure_installation

Enter the following settings:

Enter current password for root (enter for none): Just press the Enter
Set root password? [Y/n]: Y
New password: Enter password
Re-enter new password: Repeat password
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

So, to test if the setup is successful, enter the following command:

sudo mysql -u root -p 

Enter your password, and it should login you to the mysql console.

We can type ‘exit’ to exit out of the session.

How to Install MongoDB on Arch Linux

Step 5: Install PHP and Related Modules

Install PHP in Ubuntu 20.04

Run the following command to install PHP and related modules:

sudo apt install php php-mysql php-cgi php-cli php-gd
sudo systemctl restart apache2

To restart the Apache2 server.

Step 6: Create the WordPress Database

Login to MySQL and enter your password:

sudo mysql -u root -p 

Create the database wordpressdb:

CREATE DATABASE wordpressdb;
SHOW databases;

Create a database user, wpuser with new password.

See Is your password weak? And Why you should Not use a Weak Password.

CREATE USER 'wpuser'@'%' IDENTIFIED BY 'your_password_here';

Grant the user full access to the database.

GRANT ALL PRIVILEGES on wordpressdb.* to "wpuser"@"%";
FLUSH PRIVILEGES;

Step 7: Download and Install WordPress

Install WordPress on Ubuntu

To get the latest release of WordPress, go to its official download page and get the download link.

 wget https://wordpress.org/latest.zip

It should download the latest WordPress release zip file.

Install unzip and unzip the file.

sudo apt install unzip

unzip latest.zip

Now, we will copy all its content to the new directory, where we need to keep the contents of the website.

cd wordpress

sudo cp -r * /var/www/html/

Set the correct permissions for WordPress directory files.

cd /var/www/html/

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

sudo chmod -R 755 /var/www/html/

And, we need to delete the default index.html file.

sudo rm -rf index.html

Now, if we visit our Public IP Address, which is 52.183.89.27 for me, then we can see the WordPress Installation page.

Install WordPress on Apache

Now, it is just the normal WordPress Installation.

Use the database name, username and password as we had created before. For me, the setup would be:

WordPress Installation in Linux

Visit Public IP address again, there should be your WordPress Site.

In this way, we can install WordPress on Ubuntu 20.04 LTS on Apache server running on Azure Virtual Machine.

Also see Host WordPress website on Azure and Connect to Custom Domain

1 thought on “[Working] How to install WordPress on Ubuntu 20.04 Linux | Azure VM”

Leave a Comment

Your email address will not be published. Required fields are marked *