In this blog post we are discussing about how we can start the stage of converting a WordPress website into serverless using AWS cloud. In cloud platform serverless means basically we are not managing the underline servers that host our services needed. We breakdown different services needed for wordpress hosting, like Apache, MySQL, PHP etc and choose corresponding different AWS cloud serverless solutions suitable. After that integrate start integrate it with our WordPress website. There are different scenarios available to convert a WordPress website into serverless in AWS and below is the architecture diagram currently we are trying to follow.
Now the first step is to create an EC2 instance in AWS console. The steps are pretty straight forward and I have already discussed it in my old blog post. Those who are not sure about how to create an EC2 instance in AWS console, take a look at the below blog post.
Once the EC2 instance is ready, log into the server and proceed with the installation of Apache and PHP. Enable suphp for user authentication. Refer below commands.
Up to this point we have installed Apache and PHP in the server. Now lets proceed with the installation of SUPHP.
This compiles and installs suPHP on CentOS 7. Now we need to configure it to work with our Apache installation. For that create a file named /etc/httpd/conf.d/suphp.conf and add below content.
After that Create a file named /etc/suphp.conf and below content.
This completes the SUPHP configuration. But we need to proceed with the creation of virtualhost for our website, user creation and the Let’s Encrypt install for SSL.
Copy your wordpress files in it. Make user the file permissions won’t get changed after the copy. I used rync command to sync the files and folders of my existing wordpress install. Now create a file named /etc/httpd/conf.d/supporthost.in.conf and copy/paste below content.
Now install lets-encrypt and issue SSL for your website. Before issuing the command make sure your website DNS A record is already pointed to the AWS EC2 instance public IP address at your name servers end.
Now edit the file named /etc/httpd/conf.d/yourwebsite.com-le-ssl.conf and add below content in it.
Make sure all the log file defined in the virtualhost exists in the server. If its missing create those files. Otherwise there is a high change of apache service will not start after restarting it. Now for concluding the Apache,PHP install configuration steps, restart the apache service using below command.
Now lets Proceed with the RDS database creation in AWS console.
The RDS database creation is also pretty straight forward and easy. For that go the RDS console section and Click on “create database ” button. A new popup window will open and below are the few points you need to consider.
Choose the database creation method as standard.
Choose MySQL as Engine option
MySQL version is as 5.7.22 from drop down menu.
Template type as Production
In the settings section ,give the database instance name, username and password as per your desire. This will be the MySQL instance logins we use later to connect to the database instance we are going to create.
Choose the DB instance type and the storage size as per your database disk usage and resource usage.
Leave the default settings in Availability section , connectivity and database Authentication section and click on create database.
Take a look at the below screenshots too for a reference.
Now lets go to security group of this MySQL database created and allow our EC2 instance IP for port 3306 at Inbound rules section. Once that done install the MySQL client package in the EC2 instance using below commands.
After that restore the MySQL dump of your WordPress website in to the new RDS database we created using below command like below. Its just a syntax, the host, database and user will vary according to your database instance created.
Now edit the WordPress wp-config.php file and change the database instance details according to the AWS RDS instance connection string details and try to load the website. Normally the website will start loading from AWS EC2 instance and from the RDS database.