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.