Some months ago, in the final days of my previous job. My ex-manager gave me a task: To make the company's PHP WordPress marketing site fault tolerant/high availability. The site traffic is about 80,000+ visits per month. Not a lot to me but it is an order given nevertheless. I didn't have any AWS experience back then as well so I thought it is a good experience to try.
The first task is to transfer all the WordPress media files to S3 and link to them. Which turns out to be harder than expected. None of the free S3 WordPress plugins worked because they failed under mass upload of images or require either the S3 list-buckets permissions or needs CloudFront which my ex-manager is not willing to grant (He is only willing to grant S3 putObject permission on the account). I managed to find 1 free plugin that could handle mass images uploads and does not require the list-buckets permissions/Cloudfront eventually. But it is buggy and unmaintained for a few months. So I reluctantly bite the bullet and edit the plugin code directly while thinking if there is a better way*. The database is shifted to RDS in the meantime which is a much easier task.
After the 1st task is done, he launched 2 new CentOS EC2 Servers and gave me the ssh credentials to them and ask me to configure the 2 servers such that the code on both servers will always be the same.
Naturally, my 1st step is to google. As expected pretty much all the search results suggest GlusterFS or EFS. Which make sense to me since the WordPress site is usually managed by non-developers in the company as they install plugins, post content, upload files and such. Using GlusterFS and EFS would be an easy way to synchronise the files, sessions in the 2 servers with an elastic load balancer (ELB) driving traffic to them.
So I suggested that to him, hoping that he would choose EFS as the steps seem to be so much easier. However, he rejected both as he believes both gives a bad performance.
So I googled again and decided on a git push/pull model by making the wordpress site codebase a repository which was accepted by him.
Even though a solution was chosen. I kept feeling something not quite right, I can't possibly expect the non-developers to do git commit and push after they installed or update a plugin for example.
It kind of felt sad that my last task in my previous company didn't feel like a job well done at all.
So I begin slowly learning about AWS since I left my previous company last November and now I got a better solution that is so much simpler with the new knowledge I gained.
If I had the chance to do that task all over again, here is what I would do:
- Install AWS CLI on both servers
- Choose 1 of the server to be the employee server and have a subdomain mapping to it (admin.sitename.com). Employees will log in to WordPress admin through this server to manage the site.
- Continuing on the employee server, add a cron job to synchronise a transfer of all the code from the server to the S3 bucket at an interval you prefer (push). Remember to use the sync option so you incur a much lesser cost. Something like this:
- aws s3 sync --recursive /path/to/site/folder s3://my-bucket/
- On the other server, add a cron job to synchronise a transfer of all the code from the S3 bucket to the server. The reverse direction (pull).
- aws s3 sync --recursive s3://my-bucket/ /path/to/site/folder
That should be it and if we wanted to go further, we can look at EC2 auto-scaling as an option. If you know of better ways, feel free to let me know. Thanks!