Connect WordPress Application with Backend MySQL Database in AWS
This is the following task to be formed:
a. Create an AWS EC2 instance.
b. Configure the instance with Apache Webserver.
c. Download PHP application name “WordPress”.
d. As WordPress stores data at the backend in MySQL
e. Database server. Therefore, you need to set up a MySQL server using AWS RDS service using Free Tier.
f. Provide the endpoint/connection string to the WordPress application to make it work.
Let’s get started:
- Launch an EC2 instance in AWS.
2. SSH into the instance and Configure the instance with Apache Webserver, Download PHP application name “WordPress”. To do this run the following commands:
i. yum install httpd mysql -y
ii. amazon-linux-extras enable php7.4
iii. yum clean metadata
iv. yum install php php-common php-pear
v. yum install php-{cgi,curl,mbstring,gd,mysqlnd,gettext,json,xml,fpm,intl,zip} -y
vi. php -v
3. Now cd to /var/www/html. Here we will download Wordpress complete file. Run these following commands:
i. wget http://wordpress.org/latest.tar.gz
ii. tar -xzf latest.tar.gz
iii. cd wordpress
iv. mv * ../
v. cd ../
vi. rm -f latest.tar.gz
vii. rmdir wordpress/
viii. setenforce 0
ix. systemctl start httpd
x. systemctl enable httpd
4. Our application is ready but Wordpress is going to store data at backend, so we need a database server. We will use MySQL database for this purpose. So, go to RDS service in AWS and select MySQL option.
And database created.
5. Now again SSH into the EC2 instance and run the following command to connect to the database.
mysql -h endpoint -u user-name -p
In case you receive the following error and can’t log in, you need to change the security group inbound rules of the database and allow all traffic from anywhere:
ERROR 2003 (HY000): Can’t connect to MySQL server on endpoint name.
6. Now let’s configure WordPress with this database to launch our WordPress site with the help of our EC2 instance IP.
7. Copy this code of PHP, then goto /var/www/html folder and create config file with the name wp-config.php and save the copied content to this file, then restart server using:
systemctl restart httpd
Now go and complete the WordPress setup.
We did not receive any error after clicking install WordPress, which means we have successfully done the setup and connected our WordPress with the backend database server.
Thank you for reading!