I have two Amazon Linux web servers with an Amazon Load Balancer, and I want to use WordPress to display content at the document root level only. The site has other subdirectories with PHP files that are separate from WordPress. The problem is trying to keep the filesystems of the two servers in sync for the WordPress files, especially when I change a plugin or upload an image, which only affects one of the two servers at a time.

I moved WordPress into the /public directory off of document root, and then mounted /public from an AWS EFS filesystem. That way, I could mount the same EFS filesystem on both web servers.

It works great for keeping the WordPress files in sync, but it's painfully slow, both at serving web pages through Apache and also when running any command line programs (such as Mercurial) that access the /public directory. It can take 3 seconds to begin loading a WordPress page, and close to a minute for Mercurial to scan the /public directory for changes.

My first attempt at speeding this up was to use OPCache to cache the loading of the WordPress PHP files. That worked great, but I don't want it to cache all of the other PHP files I have in other directories. OPCache has a blacklist feature but I think I need a whitelist, to only cache the /public directory. But even using the blacklist for everything except /public, I still have the problem with Mercurial scans of the /public directory.

Another thought was to use something like rsync to synchronize the /public directories on the two servers but that seems like it would be slow as well, and I'd probably have to run it manually every time I made a change in WordPress that affected a file, and possibly automatically since the gallery plugin I'm using caches images by writing them into a folder.

Is there a better way to do this? It seems like it should be a fairly common thing to do.


  • 3
    Have you looked at Lsyncd - Live Syncing (Mirror) Daemon? It will watch your mirrored servers and juggle changes in almost real time...
    – gnicko
    Nov 17, 2020 at 19:49
  • @GregNickoloff - Thanks, I hadn't seen that but it appears that Lsyncd was designed to sync in one direction only. I essentially have two masters, with the same WordPress site on each server and a shared database, but with separate filesystems. I read some discussion about using it in both directions anyway, as well as using the Mirror program he linked to that supports two masters, but I was concerned about whether I could get into some kind of race condition. The more I think about this the more I wonder if WordPress just shouldn't be used behind a load balancer.
    – Russell G
    Nov 18, 2020 at 20:20
  • I'm not sure, but my inclination is that if you're getting the quantity of traffic that would require a load balancer, you probably should be considering something more robust than Wordpress.
    – gnicko
    Nov 19, 2020 at 22:55
  • @GregNickoloff - That would be good assumption, but actually I'm using it on a much larger web site with lots of other non-WordPress programs, and I need the load balancer more for being able to have two servers that I can take down independently, and for redundancy, than for heavy traffic. I actually don't expect that much traffic to the WordPress part but it happens to be on these servers behind a load balancer so it's causing some problems.
    – Russell G
    Nov 20, 2020 at 12:09


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy