Deploy WordPress on EC2
Tags: aws, cloud, ec2, wordpress
Published: 2024-01-14 17:23:03

**•Wordpress**
WordPress is a highly popular content management system (CMS). It is most commonly used for blogs but can also be used for running e-commerce sites, message boards, company websites, Portfolio Websites and many other popular use cases. In this guide, you will learn how to set up a WordPress site to run a blog.
•AWS Services services that use in this project
An Amazon EC2 instance to install and host the WordPress application.

**Implementation**
**Here are the steps on how to deploy WordPress on an EC2 instance in AWS:**

1.	Create an EC2 Instance:
2.Navigate to the EC2 service: Click on "Services" and select "EC2"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zahmkycjkf1h4mdfy7qh.png)	

3.Launch a new instance: Click on "Launch Instances"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ybhjjwyp368wenfpyfsg.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/07awt5d0xu95satf7e31.png)

4.Choose an AMI: Select a suitable Amazon Machine Image (AMI). 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qrfevajha3ntdr5onlt.png)

 
5.Choosing an instance type:

Scroll down to select an EC2 instance type. An instance type is a particular configuration of CPU, memory (RAM), storage, and network capacity.
AWS has a huge selection of instance types that cover many different workloads. Some are geared toward memory-intensive workloads, such as databases and caches, while others are aimed at compute-heavy workloads, such as image processing or video encoding.
Amazon EC2 allows you to run 750 hours per month of a t2.micro instance under the AWS Free Tier.

**Select the t2.micro instance.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ye91n6xm6tslghcskis0.png)

6. Configuring an SSH key: 
You will see a details page on how to configure a key pair for your instance. You will use the key pair to SSH into your instance, which will give you the ability to run commands on your server.
a.Open the key pair (login) section and choose Create new key pair for your instance.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s7926ib33ds99bo0upig.png)


b.You will return to Key pair (login) Section and you will find that Key has been selected.

7. Configuring a security group and launching your instance:
You need to configure a security group before launching your instance. Security groups are networking rules that describe the kind of network traffic that is allowed to your EC2 instance. You want to allow traffic to your instance:

•SSH traffic from all IP addresses so you can use the SSH protocol to log in to your EC2 instance and configure WordPress.

•HTTPS traffic from all IP addresses so that users can view your WordPress site Secured.

•HTTP traffic from all IP addresses so that users can view your WordPress site.

a. To configure this, select Allow SSH traffic from Anywhere and select Allow HTTPS & HTTP traffic from the internet

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gbbg6g5tbgjze1lbv3r6.png)
8. Configuring storage on instance.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yvn19zdp6v8kaww47iwl.png)
10. Launch:
It is now time to launch your EC2 instance.
a. Choose the Launch instance button to create your EC2 instance.
b. Wait for instance to launch.

c. You have successfully launched your EC2 instance. Click on Open address to view website.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qljrf28nogedrzqm3zhe.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/08zts16oiy6e68fzmw2r.png)

10. Allocate elastic IP :
a.Click on Ec2 dashboard
b. Click on Allocate Elastic IP

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oovhcozhxly8odz9h3qu.png)
c.To connect elastic IP click on the action and click on associate elastic IP addresses.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8f4w57vbk946rmmjudkt.png)
d.After that choose instance and click on associate.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c7ig1p5biq4jbld4un5z.png)
11. Connect to Your EC2 Instance:
•Use SSH to connect: Use a terminal or an SSH client like PuTTY to connect to your EC2 instance using its public IP address and the key pair you created earlier.

**All the commands that are executed :**
1. Install Apache server on Ubuntu
sudo apt install apache2

2. Install php runtime and php mysql connector
sudo apt install php libapache2-mod-php php-mysql

3. Install MySQL server
sudo apt install mysql-server 

4. Login to MySQL server
sudo mysql -u root

5. Change authentication plugin to mysql_native_password (change the password to something strong)
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'Testpassword@123';

6. Create a new database user for wordpress (change the password to something strong)
CREATE USER 'wp_user'@localhost IDENTIFIED BY 'Testpassword@123';

7. Create a database for wordpress
CREATE DATABASE wp;

8. Grant all privilges on the database 'wp' to the newly created user
GRANT ALL PRIVILEGES ON wp.* TO 'wp_user'@localhost;

9. Download wordpress
cd /tmp
wget https://wordpress.org/latest.tar.gz

10. Unzip
tar -xvf latest.tar.gz

11. Move wordpress folder to apache document root
sudo mv wordpress/ /var/www/html

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwqo32j4g8xdxe4r4mxo.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/134o00l4bzbhr9jg5s4x.png)
12. copy and paste the code in the terminal.

13. Command to restart/reload apache server
sudo systemctl restart apache2
OR
sudo systemctl reload apache2

14. Install certbot
sudo apt-get update
sudo apt install certbot python3-certbot-apache

15. Request and install ssl on your site with certbot
sudo certbot --apache

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dddrenfhhkumqaq42jvl.png)