One of the greatest strengths of cloud platforms like AWS is the ability to efficiently integrate various services to deploy scalable and robust applications.
In this guide, we'll go through deploying a WordPress website on Amazon Web Services (AWS) utilizing the Amazon Relational Database Service (RDS) for our database needs.
Prerequisites: Basic understanding of AWS services, especially EC2 and RDS.
Step-by-Step Deployment:
1. Setting Up RDS for WordPress: (Kindly Prefer https://kshitijaa.hashnode.dev/access-rds-from-ec2-instance )
Launch RDS Database Instance:
Navigate to the RDS dashboard in the AWS Management Console.
Click on “Create Database”
Choose a database creation method. For this guide, we'll choose "Standard Create"
For the "Engine Options," select "MySQL." WordPress supports MySQL and MariaDB, but we'll proceed with MySQL for this tutorial.
Follow the setup prompts, specifying your DB instance size, storage, and other configurations. For a test setup, the default settings should suffice.
Set the "Master Username" and "Master Password" – remember these as they'll be used when configuring WordPress.
Proceed through the remaining setup, adjusting configurations as necessary.
Modify Security Group:
Once the RDS instance is up, select it and navigate to its "Security Groups."
Edit the inbound rules to allow TCP traffic on port 3306 from the security group that your EC2 will use.
2. Setting Up EC2 for WordPress:
Launch an EC2 Instance:
From the EC2 dashboard, click “Launch Instance.”
Choose the "Ubuntu AMI" as it comes with the necessary software.
Choose an instance type. A t2.micro should suffice for small-scale testing, especially if you're eligible for the free tier.
Configure the instance details,storage and add tags if you want.
Ensure you're using the same security group as mentioned in the RDS step or one that's allowed in the RDS security group. (Default)
Launch the instance after setting up a key pair.
Your EC2 Instance is ready!
Connect and Configure EC2:
SSH into your EC2 instance.
Update the system using:
sudo apt update -y sudo apt install mysql-client -y mysql -h [RDS_ENDPOINT] -P [PORT] -u [USERNAME] -p show databases;
Adding New database as wordpress
CREATE DATABASE wordpress;
CREATE USER 'wordpress' IDENTIFIED BY 'wordpress-pass';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpress;
FLUSH PRIVILEGES;
show databases;
exit
Install the Apache web server, PHP, and necessary components:
sudo apt-get install apache2 -y
Start the Apache server and ensure it starts on boot:
sudo systemctl start apache2 sudo systemctl enable apache2
4. Installing WordPress:
Download WordPress:
Once connected to EC2, fetch the latest WordPress setup:
wget https://wordpress.org/latest.tar.gz
Extract the downloaded file:
tar -xvf latest.tar.gz
Configure WordPress to Use RDS:
Navigate to the WordPress folder:
cd wordpress
Copy the sample WordPress config file:
cp wp-config-sample.php wp-config.php
Edit the configuration using a text editor like
vim
ornano
:Locate the database details section and replace the placeholders with your RDS details:
define('DB_NAME', 'your_database_name'); define('DB_USER', 'your_master_username'); define('DB_PASSWORD', 'your_master_password'); define('DB_HOST', 'your_RDS_endpoint');
Now let's edit the Authentication Unique Keys
and Salts
. Copy the below API code and paste it into the wp-config.php
file. Refer : api.wordpress.org/secret-key/1.1/salt
define('AUTH_KEY', '--+$RG=aXK;hfS|J*01xZ-><c|Y>fB;-=S_@gX[sb_,CY~u w3u:Gj[g!e^]BIv7');
define('SECURE_AUTH_KEY', 'lXl[2P;hQ_5+WhU|SV-d.Ab+z]SUj`MU?BaA7k+X&+<{|?&-*oAG;W@q-o<gBY|X');
define('LOGGED_IN_KEY', 'd8Q6NJ1a{rE RZ>hr}xlrQVk~063^+d;}4)G2bDt@a^JPp#/$i53J%E<M5] Oc@V');
define('NONCE_KEY', 'H)};6-21jHe~HjJ<JUL3%PnRzj1k3!A^-tg|?G!v%J:w8}6:1YZ*p[zWgHM6HC?K');
define('AUTH_SALT', 'VG(~Fr?a)mR^^Q59Ojx,`-,#=7nCr;v^[B!!1Ug7CSH0mx:Cgg,;=di+/<y3Cj^q');
define('SECURE_AUTH_SALT', ':ztC0[+%SD1U0PIIFmUeb}Wc|KbKh(Er9>pV[d2H$v(4#V6P-*tv;#:2#PQFwKX1');
define('LOGGED_IN_SALT', '#&cU];~F|Acv=evUgEY5;mXcKaRx2r|B+TkQ}+:-zBXPotif{[Zm>Bd_(iYb%+Vr');
define('NONCE_SALT', 'Z%%#u|]4OdA2nQvey/XmSR,i_?:XxJ- T>%i**=oHeB-/|+I[L6.0
Now let's Deploy the WordPress site, but before that, we need to install some dependencies.
sudo apt install php libapache2-mod-php php-mysql -y
Copy the extracted WordPress files to the Apache web server document root using the command
cd ..
sudo cp -r wordpress/* /var/www/html/
Application Data Copy-paste has been done!
Restart the Apache web server & check the status using the command
sudo systemctl restart apache2
sudo systemctl status apache2
Check whether your WordPress website is working or not using
http://<public-ip>/wp-admin
Finally BOOM! This task is challenging and it took me 2 days to complete this task!
Bonus Tips:
Be careful: 1) When you Launch EC2 Instance, see its AMI (I always prefer ubuntu) and keep the right key pair (sometimes in hurry we select random key pair and later we realise we don't have it now or deleted it mistakenly ) 2) When configuring RDS, make sure to select MYSQL in this scenario, port - 3306, username and password 3) Most importantly, Make sure to be in a same network VPC and security group has 3306 port added. 4) When you edit wp-config.php
make sure to refer to the right database values. I have preferred the database username as admin where you should set it to wordpress (applicable to this example)
Conclusion:
Deploying WordPress on AWS using RDS and EC2 offers flexibility, scalability, and a high level of customization. While this guide provides a basic setup suitable for testing and small-scale operations, AWS's vast array of services can help enhance and scale your WordPress site to handle any level of traffic and complexity. Happy blogging! Thanks for reading! 😃