title: WordPress: Syncing media library between different servers
body: <p>We have three servers with the same WordPress site - a Live version, a Beta version, and a Kiosk version (a limited version of the site used for an iPad kiosk). The Beta site is deployed from a <code>beta</code> branch on GitHub, while the Live and Kiosk sites are both deployed from the <code>master</code> branch. Any differences in functionality between the sites are controlled by environment variables, beyond that they share the same code.</p>
  <p>The <code>wp-content/uploads</code> folder is shared between all three versions of the site, using a mounted Amazon EFS filesystem (couldn't use S3 due to plugin conflicts). Here's where the problem comes in.</p>
  <p>The Live and Kiosk servers share the same RDS database, so their media libraries are always in sync. However, the Beta server uses its own separate database for testing purposes - and since WP media library objects are stored in the DB, this leads to the following issues:</p>
  <ul>
  <li>When a file is uploaded to the Beta site, it isn't automatically added to the media library on the Live/Kiosk sites (and vice-versa)</li>
  <li>When a file is removed from the shared upload folder, it isn't automatically removed from the media library, leading to broken/empty media library entries.</li>
  </ul>
  <p>There's nothing necessarily wrong with this; it's just how Wordpress works. I've been circumventing the issue by using the &quot;Add From Server&quot; plugin which allows me to manually keep the media libraries in sync - but it would be nice to automate this.</p>
  <p>So I think either of the following solutions would work:</p>
  <ol>
  <li>A method to keep the &quot;media&quot; table of the two databases in sync, while keeping the rest of the tables separate</li>
  <li>A method to automatically update the media library on all 3 servers according to the content of the <code>wp-content/uploads</code> folder, which is also smart enough to ignore thumbnail versions (the &quot;Add From Server&quot; plugin unfortunately doesn't do this, so when I tried I ended up with countless &quot;thumbnails of thumbnails&quot; if that makes sense)</li>
  </ol>
  <p>Has anyone worked with a similar environment before? Any ideas regarding either of my proposed solutions, or possibly a better solution?</p>