Deploying WordPress into AWS with the help of RDS and EC2-instance.

Deepak Sharma
5 min readJan 15, 2022

--

In this article, I have deployed WordPress into EC2-instance and connect it with RDS for the backend database to store all the information.

Task Description

đź”… Create an AWS EC2 instance

đź”… Configure the instance with Apache Webserver.

🔅 Download PHP application name “WordPress”.

đź”… As wordpress stores data at the backend in the MySQL Database Server. Therefore, you need to set up a MySQL server using AWS RDS service using Free Tier.

đź”… Provide the endpoint/connection string to the WordPress application to make it work So let do this task -

So, first of all, we will launch the ec2 instance to configure the apache web server into it.So, first of all, we will launch the ec2 instance to configure the apache web server into it.

In the below screenshot, you can see the overall specifications of the instance.

Now click on launch and then connect it through putty as I had taken the image that is provided by AWS whose name is AWS Linux AMI2 which have the facility to connect via browser and if you choose another then you can connect it using putty.

Now, first of all, I will log in to the root account but it’s not good practice to login with root. You can use the sudo command to run the commands using root power from the user.

Run the below commands one by one into the terminal -

[root@-172-31-37-93 ~]# yum install httpd mysql -y
[root@-172-31-37-93 ~]# amazon-linux-extras enable php7.4
[root@-172-31-37-93 ~]# yum clean metadata
[root@-172-31-37-93 ~]# yum install php php-common php-pear
[root@-172-31-37-93 ~]# yum install php-{cgi,curl,mbstring,gd,mysqlnd,gettext,json,xml,fpm,intl,zip} -y
[root@-172-31-37-93 ~]# php -v

The above commands will setup the environment for deploying WordPress into the httpd server. Now we will download the wordpress complete file into the folder /var/www/html and unzip the file.

[root@-172-31-37-93 html]# wget http://wordpress.org/latest.tar.gz
[root@-172-31-37-93 html]# tar -xzf latest.tar.gz
[root@-172-31-37-93 html]# cd wordpress
[root@-172-31-37-93 wordpress]# mv * ../
[root@-172-31-37-93 html]# rm -f latest.tar.gz
[root@-172-31-37-93 html]# rmdir wordpress/
[root@-172-31-37-93 html]# setenforce 0
[root@-172-31-37-93 html]# systemctl start httpd
[root@-172-31-37-93 html]# systemctl enable httpd

This enable command will start the httpd server permanently so next time after reboot you don’t need to start it.

Now after these steps we will create RDS [Relational Database Service] for the backend database for running WordPress.

I will create my database using MySQL server but you can use any of these if you know the query syntax.

Here I’ll go for the free tier because I just want to test if the wordpress is working or not.

Here set your master username and password by which you can log-in into the database.

Now click on advance and give the database name in which you want to put wordpress data. You can create it by login into the database through ec2-instance but here was automatically create the database for you.

Now click on the create database

Now let check if the database is created or not. So for this, we will log-in inside to database through ec2-instance.

[root@-172-31-37-93 ~]# mysql -h Endpoint_dns -u user_name -p

Now run the query to see all the databases.

Now let configure the wordpress. Type the webserver IP into the browser and you will redirect to the below page. Select Let’s go -

Now fill the boxes with correct details -

After submitting it copy the content by pressing ctrl+C then goto ec2-instance and then goto /var/www/html folder and create config file by vi wp-config.php. Paste the copied content and save it by :wq . After this restart your httpd service by command -

[root@-172-31-37-93 html]# systemctl restart httpd

Now go to the browser and click on Run installer and then you can use your WordPress website and customize it by log-in into the wordpress console.

Click on Install WordPress after this you can use it.

So in this way, we can deploy WordPress into the AWS and connect to the database in the RDS service provided by AWS.

Thank you for reading this article….

--

--

No responses yet