WordPress is the most popular Content Management System (CMS) and powers 37% of websites and 60% of content management systems (CMS)! Many high-traffic websites such as TechCrunch, OptimistDaily, and BBC America use this CMS. Although there are so many other options, WordPress’s low cost, flexibility, and customization functionality results in its popularity. However, there is a limitation in the default WordPress configuration as traffic grows; a single server has both WordPress and the database and does not scale up. Most WordPress sites run in this configuration. Web pages eventually load slower ruining your visitor experience. To overcome this situation while staying with WordPress, a multi-tiered solution is required.
Some webmasters who only run the standard single server configuration may need help during the deployment process. Here is a brief guide on how to load balance your WordPress site.
The solution is to move to multiple database servers; this can be easily accomplished using AWS or other cloud providers. AWS offers a Relational Database Service (RDS) that uses SQL for maintaining and querying the data. First, you need to open the RDS console and create a new database from your dashboard. You will be prompted to specify the DB details. Although there are default settings for this, pay attention to the DB instance class and Multi-AZ deployment.
For security, create a DB username and password to securely access your DB and relay information. Under the Database option, type DB name and note down your DB port value to be used later. Have a sneak around the other default settings and click “Create Database”. The next step is to modify the ingress rules on RDS instance’s security group. To do this, go to the Amazon RDS console and choose a database to view its details. Under security settings, note the Security Groups and Endpoints. This can come in handy later on.
Under the security section, you will also see the security group associated with your DB instance. Click on the link to view the security group in the EC2 Console. Once open, choose “Inbound” in security group details. Click “Edit” and then add your Rule and Type and select mysql that your application uses. Lastly, modify the source table or type “sg-” to view a list of available security groups. Click ‘save’ and let the configuration take place.
Meanwhile, download WordPress along with the configuration files since you will need it later to deploy it on your server. Extract WordPress in your directory and the configuration files over the WordPress installation.
As you do this, you are already halfway to deploying your first WordPress website using Amazon RDS. But we still need to work around with the Elastic Beanstalk Environment (EBE).
Use the AWS Management Console to create an EBE. You also need to choose the PHP platform and accept the default settings and sample code. Click on Configure more settings, select high availability, scroll down and click on modify Auto Scaling group. Select number of max servers as additional servers will be billed as per standard charges. Click save and on the next screen click create. Once you create the ‘’Environment’’ you can configure and connect it to the database created earlier.
Upon successful configuration, deploy the WordPress code to the environment you downloaded from the repository. You can also launch the Elastic Beanstalk console. Upon loading, you need to choose the language of the platform such as English, Spanish or Arabic, etc.
For Application Code, choose the sample application and then click on ‘‘Review and Launch’’. You will be prompted to review the options, and once you are satisfied, hit “Create App”. The creation of the environment takes a few minutes and creates the following six resources.
- EC2 Instance
- Instance Security Group
- Load Balancer
- Load Balancer Security Group
- Auto Scaling Group
- AWS Cloud Formation Stack and a Domain Name
Elastic Beanstalk will manage all of the above resources. So make sure to not terminate your environment as it will terminate all your resources. The Amazon RDS DB is launched outside of the environment so you will also need to carefully manage its life cycle.
Make sure to configure and verify the structure of your WordPress Beanstalk Folder. You need to configure the environment property section by providing a database endpoint username and password mentioned above.
Finally, you can install WordPress and have your website up and running. To complete the installation, open the Elastic Beanstalk Console and navigate to the management page for your environment. Choose the environment URL to open your site in a browser and you will automatically be redirected to the WordPress installation Wizard.
Perform the standard installation. Since the database is already connected to the environment, you won’t be prompted to configure the DB. Installation takes a few minutes to complete, after which you can successfully run your load-balanced WordPress using AWS.