Table of contents
- Why we need to use RDS?
- TASK: Deploy WordPress with Amazon RDS
- 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
- Conclusion
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, We will see how to set up a WordPress blog site.
Here’s the guide to official documentation from AWS: Deploy WordPress with Amazon RDS.✨
Before getting ahead, let us know why we need to use RDS.
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.
TASK: Deploy WordPress with Amazon RDS
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.
Launch an EC2 Instance with the below details:
1. Name: WordPress
2. AMI: Ubuntu
3. Number of instance: 1
4. Instance type: t2.micro
5. Key-pair: Select or create a key-pair
6. Network Settings: Check the boxes “Allow HTTPS traffic from the Internet” & “Allow HTTP traffic from the Internet”
7. And leave the other options as it is.Click on "Launch Instance".
Go to your instance created now named
WordPress
. And Configure Configuring the security group to allow inbound traffic on the MySQL port (default is 3306).
Step 2: 🛠️ Set Up an Amazon RDS for MySQL Database
Navigate to RDS: In the AWS Console, go to the Amazon RDS service.
Create a New RDS Instance. Click on "Create Database".
In Choose a database creation method, choose the "Standard create" and in Engine options, select "MySQL".In Templates, Select "Free Tier".
Under Settings, provide the following details:
DB instance identifier: wordpress-rds
Credentials Settings: -
Master username: admin
And provide the password of your choice according to the constraints mentioned.(Note down it somewhere, we will need it later)
In Instance Configuration, default it is db.t3.micro.
In Storage, leave it is as default.
In Connectivity, Select "Connect to an EC2 compute resource" and select the instance we have created in Step 1.
Configure other settings like VPC, and security groups according to your requirements.
Review the configuration and click “Create Database”.
Note: RDS creation takes a few minutes.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
Navigate to IAM.
Create and Assign an IAM Role to EC2 Instance. Click on Roles on the left side under Access management.
Click on "Create Role".
In Select trusted entity, Select AWS Service and Select the EC2 service .
In permission policies, attach the permission
AmazonRDSFullAccess
.Name the role as “WordPress-EC2-Role”.
Click on "Create Role".
Assign the IAM Role to an EC2 Instance.
Select the EC2 instance to which you want to assign the IAM role.
In the instance details pane, click on “Actions.”
Choose “Security,” and then click on “Modify IAM Role.”
Select the role we have created for our instance named WordPress-EC2-Role.
Click on "Update IAM Role".
Step 4: 🔄 Connect EC2 to RDS Using MySQL Client
Now, Let’s connect to the EC2 instance using SSH.
And then install the MySQL client in the instance using below commands.
sudo apt-get update sudo apt-get install mysql-client mysql --version
Now, Connect to the RDS instance using the MySQL client using the below command.
mysql -h <RDS_ENDPOINT> -P <RDS_PORT> -u <MASTER_USERNAME> -p # mysql -h wordpress-rds.cfsy86oycg5j.us-east-1.rds.amazonaws.com -P 3306 -u admin -p
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
To run WordPress, you need to run a web server on your EC2 instance. So, To install Apache on your EC2 instance, run the below command.
sudo apt-get install apache2
To start the Apache web server, run the below command.
sudo systemctl restart apache2
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 below commands.
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 below command.
ls
Go to the WordPress directory and create a copy of the default config file using the below commands.
sudo cp wp-config-sample.php wp-config.php sudo vim wp-config.php
Edit the database configuration by changing the following lines.
In DB_NAME: wordpress(which we have given while creating database in Step5)
In DB_Username: admin
In DB_Password: What you have set while creating "WordPress-EC2-RDS"In DB_HOST: Your RDS Endpoint
In Authentication Unique Keys and Salts.
You can generate the content of this section from this link: WordPress secret-key.
Replace with the existing content.
Install the application dependencies you need for WordPress. In your terminal, run the below 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 . /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
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.
And now we have no resources that we can be charged for.
Conclusion
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.
Hope you find it helpful🤞 So I encourage you to try this on your own and let me know in the comment section👇 about your learning experience.✨
👆The information presented above is based on my interpretation. Suggestions are always welcome.😊
~Smriti Sharma✌