Deploy WordPress on EC2

On-cloud7 - Jan 14 - - Dev Community

•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

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

Image description

Image description

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

Image description

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

  1. 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

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

  1. 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

  1. Configuring storage on instance.

Image description

  1. 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

Image description

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

Image description
c.To connect elastic IP click on the action and click on associate elastic IP addresses.

Image description
d.After that choose instance and click on associate.

Image description

  1. 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

Image description

  1. copy and paste the code in the terminal.

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

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

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

Image description

. . . . . . . . . . . . . . . . . . . . . . . . . .