Deploy WordPress website on AWS
TABLE OF CONTENTS
Step 1: 🚀 Launch an Amazon EC2 Instance
Step 2: 🛠️ Set Up an Amazon RDS for MySQL Database
Step 3: 🔐 Create an IAM Role for EC2 with RDS Full Access
Step 4: 🔄 Connect EC2 to RDS Using MySQL Client
Step 5: 🌐 WordPress DB Creation and Apache Server Installation
Step 6: 📝 Set up the server and post your new WordPress app.
Step 7: 🌐 Explore the Newly Set Website and Clean Up
Over 30% of all websites use WordPress as their content management system (CMS). It is often used to run blogs, but it can also be used to run e-commerce sites, message boards, and many other famous things. In this blog, I will show you how to set up a WordPress blog site.
Here’s the guide to official documentation from AWS to deploy this project.
Before getting ahead, let us know why we need to use RDS:
- Database maintenance for your WordPress site is critical. Your database instance holds all of your important data for your WordPress site. If the database goes down, your website may go down with it, and you could even lose your data.
- Database maintenance can also be difficult, and database administrators have years of specialized experience. When setting up a WordPress site, you want to stay focused on designing your page and generating your content, not worrying about database performance and backups.
Amazon RDS for MySQL helps with both of these problems. Amazon RDS for MySQL is a managed database offering from AWS. With Amazon RDS for MySQL, you get:
- Automated backup and recovery so that you won’t lose data in the event of an accident
- Regular updates and patches, keeping your database secure and performant
- Easy installation with smart default parameters.
Let’s start the project now.
We can divide this project into seven sections, for us to make it easy to understand:
Step 1: 🚀 Launch an Amazon EC2 Instance
Step 2: 🛠️ Set Up an Amazon RDS for MySQL Database
Step 3: 🔐 Create an IAM Role for EC2 with RDS Full Access
Step 4: 🔄 Connect EC2 to RDS Using MySQL Client
Step 5: 🌐 WordPress DB Creation and Apache Server Installation
Step 6: 📝 Set up the server and post your new WordPress app.
Step 7: 🌐 Explore the Newly Set Website and Clean Up
Step 1: 🚀 Launch an Amazon EC2 Instance
- Navigate to EC2: In the AWS Console, go to the Amazon EC2 service. 🚀
2. Launch an EC2 Instance:
- Click on “Launch Instance” to create a new EC2 instance. 🚀
- Choose an Amazon Machine Image (AMI) that suits your requirements. A common choice is an Amazon Linux AMI. 📦
- Select an instance type based on your website’s expected traffic and resource needs. ⚙️
- Configure the instance details, including network settings, subnet, and IAM role (if required). 🛡️
- Add storage based on your needs. A recommended practice is to have enough storage to accommodate your website files. 🗂️
- Configure security groups to allow incoming traffic on ports 22 (SSH), 80 (HTTP) and 3306 (MySQL) to the EC2 instance. 🔒
3. Create or Use an Existing Key Pair: If you don’t have an existing key pair, create a new one. You’ll use this key pair to access your EC2 instance securely via SSH. 🔑
4. Launch the EC2 Instance: Once you’ve reviewed your instance configuration, launch the instance. AWS will create it, and you can view the status in the EC2 Dashboard. 🚀
Step 2: 🛠️ Set Up an Amazon RDS for MySQL Database
- Log in to AWS Console: Open your AWS Management Console.
- Navigate to RDS: In the AWS Console, go to the Amazon RDS service. 🖥️
3. Create a New RDS Instance:
- Click on “Create Database” to start the RDS creation process. 📦
- Choose “MySQL” as the database engine since WordPress requires it. 🗄️
- Select the appropriate version and edition based on your requirements. ⚙️
- Configure your database instance details, including instance class, storage, and instance identifier. Make sure to set up a strong master username and password for database access. 📝
- Adjust advanced settings as needed, including VPC, security groups, and backups. 🧩
- Finally, create the RDS instance by clicking “Create Database.” 🚀
4. Wait for Database Creation: It may take a few minutes for the RDS instance to be created. Monitor the progress in the RDS Dashboard. 🕒
5. Retrieve Database Endpoint: Once the RDS instance is available, note down the endpoint URL. You’ll need this information to configure WordPress later. 🌐
Step 3: 🔐 Create an IAM Role for EC2 with RDS Full Access
1: Log in to AWS Console 🔐
- Go to the AWS Management Console.
2: Navigate to IAM 🚀
- In the AWS Console, navigate to the “Services” menu.
- Select “IAM” (Identity and Access Management) under the “Security, Identity, & Compliance” section.
3: Create and Assign an IAM Role to EC2 Instance 🛠️
- In the IAM Dashboard, click on “Roles” in the left navigation pane.
- Click the “Create role” button.
3. Choose “AWS service” as the trusted entity type.
4. Under “Choose the use case,” select “EC2” as the service that will use this role.
5. Click “Next: Permissions.”
6. In the “Permissions” step, attach the necessary policies. To grant full access to Amazon RDS, search for and attach the “AmazonRDSFullAccess” policy. You can also attach additional policies as needed for your use case.
7. Click “Next: Tags”.
8. Provide a meaningful name for the role in the “Role name” field.
9. Optionally, add a description for the role in the “Role description” field.
10. Click the “Create role” button.
4: Assign the IAM Role to an EC2 Instance 🔄
- Go to the EC2 Dashboard in the AWS Console.
2. Select the EC2 instance to which you want to assign the IAM role.
3. In the instance details pane, click on “Actions.”
4. Choose “Security,” and then click on “Modify IAM Role.”
5. In the “IAM role” dropdown, select the IAM role you just created.
6. Click “Apply”
The IAM role is now assigned to the EC2 instance, granting it full access to Amazon RDS. You’ve successfully created and assigned an IAM role with the necessary permissions. 🎉
Step 4: 🔄 Connect EC2 to RDS Using MySQL Client
- SSH into your EC2 instance using the key pair you saved during the EC2 instance setup.
ssh -i your-key-pair.pem ec2-user@your-ec2-instance-ip
2. Update your EC2 instance by running:
sudo apt update -y
3. Install the MySQL client on your EC2 instance:
sudo apt install mysql-server -y
4. Connect to your RDS MySQL instance using the credentials you noted in Step 1:
mysql -h <endpoint address> -P <port.no> -u <username> -p
5. Enter the MySQL password when prompted.
6. You are now connected to your RDS MySQL instance via your EC2 instance using the MySQL client.
Step 5: 🌐 WordPress DB Creation and Apache Server Installation
- Create a database user for the WordPress application and give the user permission to access the WordPress database.
CREATE DATABASE wordpress;
CREATE USER 'wordpress' IDENTIFIED BY 'wordpress-99';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpress;
FLUSH PRIVILEGES;
Exit
2. To run WordPress, you need to run a web server on your EC2 instance.
To install Apache on your EC2 instance, run the following command in your terminal:
sudo apt-get install apache2
3. To start the Apache web server, run the following command in your terminal:
sudo systemctl restart apache2
4. You can see that your Apache web server is working by browsing the public-IP of your ec2 instance.
Step 6: 📝 Set up the server and post your new WordPress app.
Download and uncompressed the WordPress software by running the following commands in your terminal:
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
Now we will see a tar file and a directory called WordPress with the uncompressed contents using the ls command.
Change the directory to the WordPress directory and create a copy of the default config file using the following commands
Now create a copy of the config file and edit the wp-config.php file
sudo cp wp-config-sample.php wp-config.php
sudo vim wp-config.php
Edit the database configuration by changing the following lines:
Authentication Unique Keys and Salts:
You can generate the content of this section from this link: https://api.wordpress.org/secret-key/1.1/salt/.
Replace with the existing content.
Install the application dependencies you need for WordPress. In your terminal, run the following command.
sudo apt install php libapache2-mod-php php-mysql -y
Copy your 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
sudo systemctl restart apache2
Browse public-ipv4address/wp-admin/ you should see the WordPress welcome page.
http://Public_IPv4/wp-admin
And yay! You have your own WordPress website.
Now let’s step into the final section of this Project.
Step 7: 🌐 Explore the Newly Set Website and Clean Up
Once you have explored, we need to clean up the resources so that we can avoid being charged.
Delete your EC2 instance first and then the RDS.
Delete the RDS instance now:
And we have no resources that we can be charged for.
In this blog, we’ve outlined a step-by-step guide to deploying a WordPress website on AWS. From launching an EC2 instance to exploring the final result, we’ve covered all the essential steps. Plus, by following this project, you can enhance your AWS skills and even add it to your resume.
Share your thoughts in the comments and connect with me on LinkedIn(Mudit Mathur) for suggestions and corrections. Stay tuned for more valuable content! #Day45 #90daysofdevops