How to Install WordPress on AWS Apache 2 Ubuntu 22.04

How to Install WordPress on AWS Apache 2 Ubuntu 22.04

To install WordPress on Amazon EC2 Ubuntu 18.04|20.04|22.04, Start ssh terminal and connect aws ec2 instance, And type sudo apt-get install lamp-server command to install lamp stack, and then type wget command on ubuntu aws ec2 ssh terminal window to install latest wordpress.

WordPress installation and configuration on Amazon AWS ubuntu web server are very simple things. Because the Ubuntu community provides several commands to install and configure lamp (Linux, apache, MySQL, and PHP) on AWS server. As well as the WordPress community.

How To Install WordPress in Amazon AWS EC2 Ubuntu 18.04|20.04|22.04 With LAMP Stack

Here are steps to install lamp(Linux, apache 2, PHP and MySQL) and WordPress on Ubuntu 18.04|20.04|22.04 with amazon aws ec2 instance server:

Step 1 – Launch New AWS ec2 Instance

First of all, you need to launch the AWS EC2 instance. If you have already launched a new ec2 instance, you can move next step. Otherwise, you need to read this tutorial => How to launch ec2 instance in aws step by step.

Step 2 – Connecting your AWS EC2 Instance from SSH

In this step, you need to connect your AWS EC2 instance from the ssh terminal. If you are new to connecting AWS EC2 instance with Windows, Ubuntu, and Mac systems. So you can read this tutorial => How to Connect to ec2 Instance From Putty and SSH Terminal.

Step 3 – Install Apache 2 on Ubuntu 18.04|20.04|22.04

Here are some commands to install Apache on ubuntu 18.04|20.04|22.04 on your virtual aws ec2 instance server:

3.1 – Update Ubuntu System Repositories

sudo apt update

3.2 – Update Ubuntu System Repositories

sudo apt install apache2

3.3 – List the UFW application profiles

sudo ufw app list

3.4 – sudo ufw allow ‘Apache Full’

sudo ufw allow 'Apache Full'

3.5 – Verify that the Apache service is running

sudo systemctl status apache2

3.6 – Open Browser and type EC2 intance IP

Finally, open your browser and type your AWS ec2 instance IP address. And, it will be looks like the Apache 2 page in the following picture:

install apache 2 web server on amazon ec2
install apache 2 web server on amazon ec2

Step 4 – Install MySQL on Ubuntu 18.04|20.04|22.04

4.1 – Installing MySQL server

Now, open your ssh terminal and type the following command to install MySql Server:

sudo apt-get install mysql-server

4.2 – Securing MySQL server in Apache aws ec2

Then, secure MySql server by using the following command. So, you will need to set the root password of the database and secure it using the following command :

sudo mysql_secure_installation

When you run this command. Then the questions given below in the prompt will appear:

  • You will be presented with a screen where MySQL asks whether you would like to activate the VALIDATE PASSWORD PLUGIN. For now, keeping things simple, type no.
  • In the next type the root password of your choice. Confirm it again.
  • In the next screen MySql will ask whether to remove anonymous users. Type yes
  • Disallow root login remotely? Type No
  • Remove test database and access to it? Type Yes
  • Reload privilege tables now? Type Yes
  • After the password has been set you can check the whether MySQL is working correctly by logging into the database with the command :
sudo mysql -u root -p

The above command will ask for the password. Password is the same that was set in the previous step.

4.3 – Create MySQL User

Now, Create a user named ‘test’. you can choose the user name anything you want.

mysql> CREATE USER 'test'@'localhost' IDENTIFIED BY 'Password';

4.4 – Grant Permission To User

Now, type the following command on ssh terminal to grant permission of user.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost';

4.5 – Reload all privileges


4.6 – Create Database For WordPress Website

Now create a new database for wordpress website. So, type the following command on your ssh terminal to create database that named wp_aws:

mysql> CREATE DATABASE wp_aws;

Now, use the exit command to exit from MySql:


Step 5 – Install PHP on Ubuntu 18.04|20.04|22.04

To install php on Ubuntu 18.04|20.04|22.04, you can do it by using the following steps:

5.1 – Install PHP and Common Extensions

Now, install PHP with it’s common extensions. So open your ssh terminal and type the following command:

sudo apt-get install php libapache2-mod-php php-mysql php-curl php-gd php-json php-zip php-mbstring

5.2 – Edit dir.conf File

After successfully installed PHP on ubuntu amazon ec2 instance. Now, you need to configure dir.conf file by using the following sudo nano command:

sudo nano /etc/apache2/mods-enabled/dir.conf

It will look like this:

<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.php index.xhtml index.htm

Move the PHP index file to the first position after the DirectoryIndex specification, like this:

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.xhtml index.htm

5.3 – Restart Apache Web Server

After successfully installed PHP MySQL and configure these on ubuntu amazon ec2 instance.

Finally, You need to restart Apache 2 server by using the following command:

sudo service apache2 restart

Step 6 – Install WordPress on Ubuntu 18.04|20.04|22.04 AWS EC2 Instance

Here are some commands to install wordpress on ubuntu 18.04|20.04|22.04 on your virtual aws ec2 instance server:

6.1 – Installing WordPress

Use the below command to download the latest version of WordPress on the EC2 instance:


6.2 – Extract wordpress setup tar file

Type the below command on your ssh terminal to extract wordpress setup tar file:

tar -xvzf latest.tar.gz

6.3 – Move the extracted file contents to /var/www/html Directory

Use the below command to move all extracted file contents of wordpress to /var/www/html directory:

sudo mv -f wordpress/* /var/www/html

6.4 – Enable Permission to Apache 2 User

Type the following command on ssh terminal to enable permissions on the WordPress folder to the apache2 user:

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

6.5 – Type Your instance Ip Address On Browser

Now, you need to type aws instance ip address on browser and looks like the following screen:

Then click on let’s go button. After that, you need add your database name, username, password, Sitename, and email on next screen.


Congratulations, you have successfully installed lamp (linux, apache 2, php and mysql) and wordpress on amazon(aws) ec2 ubuntu.

Recommended AWS Tutorial


Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

2 replies to How to Install WordPress on AWS Apache 2 Ubuntu 22.04

  1. 3.2 and 3.3 have the same commands?

  2. Please how can SSL certificate be enabled on the Ubuntu Ec2 instance?

Leave a Reply

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