How to Deploy a WordPress Website in AWS EC2

A VPN is an essential component of IT security, whether you’re just starting a business or are already up and running. Most business interactions and transactions happen online and VPN

Creating EC2 Instance

Immediately after logging in my AWS account, I navigated to the top left corner and clicked on Services -> Compute -> EC2

And then clicked on “Launch instance” .

I gave my instance the default name “My Web Server”, and chose “Ubuntu” as my operating system. I left the Instance type as the default “t3.micro”.

I then scrolled down and created a new key pair which I named “mywebserver”. The key pair type was “RSA” and the private key file format was “.pem” because I am on a mac, if I was using a windows machine I would have use the “.ppk” file format instead. The key pair file was automatically downloaded.

I gave permissions to allow HTTP and HTTPS traffic from the internet by checking the boxes.

And lastly, I clicked on “Launch instance”.

Assign Elastic IP Address

On the EC2 dashboard, on the left pane under “Network & Security”, I clicked on “Elastic IPs”. Then click on “Allocate Elastic IP address” on the top-right side. In the Tags, add “Name” — “mywebserverIP” & click on “Allocate”.

Click on “Actions” and on the dropdown menu click on “Associate Elastic IP address”

Choose “Instance” as your Resource type. On the dropdown menu under Instance choose the relevant instance you are working on and click on “Associate”.

Lastly, confirm that the new Public IPv4 address is associated with the relevant instance.

Connect to AWS EC2 Instance via SSH

  1. Open your Mac Terminal, and navigate to the folder with your key pair downloaded from earlier on. In my case, its in my Home folder.
  2. chmod 400 your-key-pair-file-name
  3. ssh -i “your-key-pair-file-name” ubuntu@your-public-ip-address

When prompted, Are you sure you want to continue connecting (yes/no/[fingerprint])?, type yes and press enter and you will be connected!

Installing Apache Webserver on AWS EC2 Instance

On your terminal, while still connected to your instance, run the command sudo apt install apache2

To confirm that your Apache2 webserver was installed successfully open the url http://your-public-ip-address. Successful installation will show the will show the default apache page.

Installing PHP on AWS EC2 Instance

WordPress is built on PHP, and we will need MySQL for the wordpress database.

To install PHP, run the the command sudo apt install php libapache2-mod-php php-mysql

To install MySQL server, run the command sudo apt install mysql-server

To be able to install WordPress successfully, change MySQL authentication plugin to MySQL native password so that we can login the MySQL server with a normal password. To login to MySQL server, run the command sudo mysql -u root

Change authentication plugin to mysql_native_password (Put whatever password you like to set and change the password to something strong), Command :- ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password by ‘Yourpassword’;

To change the authentication plugin to native password, run the command ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password by ‘Your_password_here’;

To create a new database user for WordPress, run the command CREATE USER ‘wp_user’@localhost IDENTIFIED BY ‘Your_password_here’;

To create a database for wordpress, run the command CREATE DATABASE wp;

Lastly, grant all the database wp privileges to the wp_user, run the command GRANT ALL PRIVILEGES ON wp.* TO ‘wp_user’@localhost;

Click Ctrl+D to exit MySQL window.

Installing WordPress on AWS EC2 Instance

Navigate to directory /tmp, by running the command cd /tmp

To download wordpress, visit the wordpress official website and copy the link https://wordpress.org/latest.tar.gz, then run the command wget https://wordpress.org/latest.tar.gz

To unzip the downloaded file run the command tar -xvf latest.tar.gz

To locate the wordpress folder, run the command ls

Move the wordpress folder to document root of Apache web server by running the command sudo mv wordpress/ /var/www/html

Navigate to Apache root directory by running the command cd /var/www/html

Open you url http://your-public-ip-address and append /wordpress, so that the whole url is http://your-ip-address/wordpress, and then click on Let’s go!

Fill in the form accordingly, use the same details you used earlier on when configuring the MySQL server.

When I get the wp-config error, manually create the wp-config.php file by first copying the code, and on the terminal navigate to wordpress by running the code cd wordpress and then vi wp-config.php to create the file. Lastly, I paste my code and save the file then “Run the installation”.

Provide the required information and login to you wordpress backend!

Picture of admin

admin

Leave a Replay

About Me

Telecommunications Engineer | Full-stack Developer | Cloud and Internet Security Enthusiast. 

Recent Posts

Follow Us

Weekly Tutorial