DAY 45: Deploy WordPress website on AWS

DAY 45: Deploy WordPress website on AWS

Over 30% of all websites on the internet use WordPress as their content management system (CMS). It is most often used to run blogs, but it can also be used to run e-commerce sites, message boards, and many other popular things. This guide will show you how to set up a WordPress blog site.

Task 1:

As WordPress requires a MySQL database to store its data ,create an RDS as you did in Day 44

To configure this WordPress site, you will create the following resources in AWS:

  • An Amazon EC2 instance to install and host the WordPress application.

  • An Amazon RDS for MySQL database to store your WordPress data.

  • Setup the server and post your new Wordpress app.

🔏step1: Log in to the AWS console and Go to the Amazon RDS console.

  • Click on "Create database" and Select "MySQL" as the engine type.

✔step2: Choose the "Free tier" template for the "DB instance class".

✏step3: Enter a unique name for the "DB instance identifier".

📁step4: We are using instance class "db.t3.micro".

💽step5: In storage section this instance has "gp2" as default storage type with 20 GiB storage. Unchecking "Enable storage autoscaling".

💨step6: Choose 'Default VPC'

🔐step7: Uncheck "Enable automated backup" from "Backup" section.

📂step8: Scroll it down all the way to bottom and click on "Create database".

✨✨step9: The database is created.

An Amazon EC2 instance to install and host the WordPress application.

✔step1: Go to the Amazon EC2 console., Click "Launch Instance", we are Choosing a ubuntu AMI.

✏step2: Create a name to instance .

In this task, we are using "Ubuntu" AMI here.

🔑step3: Select "Free tier eligible" instance type "t2.micro". and using a key created previously. It will be used to connect to EC2 instance.

⚙step4: In "Network settings", select VPC, Subnet and security group as shown and We have HTTP & SSH traffic allowed in inbound rule

❄step5: Scroll it down to bottom and click on "Launch instance" to launch it.

Check the status on EC2 dashboard as Instance has created.

  1. An Amazon RDS for MySQL database to store your WordPress data.

    Choose the MySQL database you created, go to the Connectivity & Security tab in the display and choose the security group listed in VPC security groups. The console will take you to the security group configured for your database.

    • Select the Inbound Rules tab, then choose the Edit inbound Rules button to change the rules for your security group.

  • Now, connect the EC2 instance from local using "SSH client".

    • Run the following command in your terminal to install a MySQL client to interact with the database.

         sudo apt install mysql-client -y
      

      • To check the "MySQL" version, use the command given below-
            mysql --version

  • Go to the RDS instance and copy the "Endpoint" as shown below.

  • In terminal, enter the following command to set an environment variable for our MySQL host.

    • Be sure to replace “<your-endpoint>” with the hostname of our RDS instance.
    export MYSQL_HOST=<your-endpoint>
    

  • Run the following command in terminal to connect to our MySQL database. Replace “<user>” and “<password>” with the master username and password we configured when creating our Amazon RDS database.

            mysql --user=<user> --password=<password> wordpress

Note: Here, "wordpress" is the database name.

  • Finally, create a database user for our WordPress application and give the user permission to access the "wordpress" database.

Run the following commands in terminal:

            CREATE USER 'wordpress' IDENTIFIED BY 'wordpress-pass';
            GRANT ALL PRIVILEGES ON wordpress.* TO wordpress;
            FLUSH PRIVILEGES;
            Exit

Configure WordPress on EC2:

Now, Let's configure the WordPress on our EC2 instance.

  • To run WordPress, we need to run a web server on our EC2 instance. The open source "Apache web server" is the most popular web server used with WordPress.

First, update the system using below command,

            sudo apt update

To install Apache on our EC2 instance, run the following command in terminal:

            sudo apt install -y apache2

Start the Apache service and check the status using below command

            sudo systemctl start apache2
            sudo systemctl status apache2

  • We can see that your Apache web server is working and that our security groups are configured correctly by visiting the public DNS of our EC2 instance in the browser.

  • Go to the EC2 Instances page and find our instance. In the Description below, find the Public IPv4 DNS of our instance.

  • In this step, we will download the WordPress software and set up the configuration.

  • First, download and uncompressed the software by running the following commands in terminal:

      wget https://wordpress.org/latest.tar.gz
      tar -xzf latest.tar.gz
    

  • Run "ls" to view the contents of our directory, can see a tar file and a directory called "wordpress" with the uncompressed contents.

  • Change the directory to the "wordpress" directory and create a copy of the default config file using the following commands:

      cp wp-config-sample.php wp-config.php
    

    Open the wp-config.php file

    • DB_NAME: your RDS database name

    • DB_USER: The name of the user you created in the database in the previous steps

    • DB_PASSWORD: The password for the user you created in the previous steps

    • DB_HOST: The hostname of the database means your database endpoint

The second configuration section we need to configure is the "Authentication Unique Keys and Salts".

  • Go to the link api.wordpress.org/secret-key/1.1/salt to generate values for this configuration section. We can replace the entire content in that section with the content from the link.

    • In this step, we will make our Apache web server handle requests for WordPress.

    • First, install the application dependencies we need for WordPress. In terminal, run the following command:

            sudo apt install php libapache2-mod-php php-mysql -y

Second, change to the proper directory by running the following command:

            cd ..

Then, copy WordPress application files into the /var/www/html directory used by Apache:

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

Finally, restart the Apache web server to pick up the changes:

            sudo systemctl restart apache2

We can see the WordPress welcome page with

  • http://<EC2_instance_ip/hostname>/wp-admin using the URL shown below .

    Successfully deployed a WordPress website on AWS

    In this blog, we successfully deployed a WordPress website on AWS, leveraging services like Amazon EC2 and Amazon RDS . In the next blog we will explore more on AWS .

    Thank you for 📖reading my blog, 👍Like it and share it 🔄 with your friends.

    Happy learning😊😊