Search code examples
wordpressamazon-web-servicesload-balancing

Load-balance wordpress site


I would like to have a scalable infrastructure for my wordpress site. We currently have the following:

  • A cloudfront that serves the website
  • A load balancer and target group with only one registered target in it
  • An RDS.
  • The WP server (on which config, and wp-content is).

We have several thousands of pages in the wordpress instance, and sometimes we need to make changes, invalidate caches in the cloudfront to serve the new content. Doing this on a lot of pages can create a huge load on the server, and make it unreachable or super slow. So we thought about adding an autoscaling group, which would spin up new instances if the load is too high, and remove then when necessary.

To do so, I believe we need to move the wp-content folder to a shared directory (between all the servers). Is it a correct assumption first of all? So I naturally created an EFS, which I mounted on a copy of my wordpress server, then rsync all the files with permissions in the efs. Then as suggested all over the net, I added the following in my wp-config.php: define('WP_CONTENT_DIR', '/mnt/efs/wp-content'); where /mnt/efs/wp-content is directory on the efs. From this point, the website worked as expected, I could see some traffic on the EFS monitoring page when viewing pages.

To make sure all the files are correctly shared and copied in the wp-content, I deleted /data/app/wp-content/ folder (it shouldn't be used, as I referenced wp-content to be in my efs). And my site started acting weirdly. Some formatting disappeared, buttons are native and not customized etc. The console shows a lot of 404 also with following errors:

www.mysite.eu/:1 Access to font at 'https://www.mysite.fr/wp-content/themes/mysite/dist/fonts/icomoon/icomoon.ttf' from origin 'https://www.mysite.eu' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

GET https://www.mysite.fr/wp-content/plugins/js_composer/assets/lib/bower/font-awesome/webfonts/fa-solid-900.woff net::ERR_FAILED 200

Looks like there are no fonts, no plugins, no themes anymore. So, quite a few questions:

  • Do I need to keep both local wp-content and shared wp-content? If so, if I install a plugin or a theme, would it be available for other servers as well?
  • Do I really need an EFS? Or data is fully stored in DB, and wp-content can live on its own for each server?
  • Are there any other steps in moving the wp-content folder? Maybe specific steps for some plugins?
  • Is my architecture lacking anything for what I would like to achieve (scale up and down based on demand), or does that make sense?

Thank you!


Solution

  • Don't put wp_content on a shared file system (s3 bucket). It contains a lot of theme and plugin code, and running code from s3 can cause performance trouble and crank up IOPS costs. Instead, use a plugin to offload your site's uploaded media files (jpg, etc) to the s3 bucket, then clone the site.

    Use a shared persistent object cache if you can. redis is a good choice.

    AWS has a tutorial about doing this, without the cache, on Lightsail. https://aws.amazon.com/getting-started/hands-on/launch-load-balanced-wordpress-website/