You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多服务器部署的WordPress站点媒体库同步问题咨询

Hey Keith, great question—since you're already sharing the wp-content/uploads folder, the file sync part is mostly covered, but WordPress stores critical media metadata (like attachment titles, alt text, and links) in the database, so we need to address both layers to get full media library sync across your three sites. Here are the most practical approaches tailored to your setup:

1. Database Attachment Record Sync (For Near-Real-Time Alignment)

Since your codebase is identical across sites (only environment variables differ), the core issue is syncing the attachment-related records in the WordPress database.

  • Scripted Database Export/Import (Low-Cost, Reliable)
    Use mysqldump to export only the media-related records from your Live site, then import them to Beta and Kiosk. This avoids syncing unrelated post data.

    • Example export command (targets only attachments):
      mysqldump -u your_db_user -p your_live_db wp_posts wp_postmeta --where="wp_posts.post_type='attachment'" > media_sync.sql
      
    • Before importing to Beta/Kiosk, update domain references if your sites use different URLs:
      sed -i 's/https://your-live-domain.com/wp-content/uploads/https://your-beta-domain.com/wp-content/uploads/g' media_sync.sql
      
    • Schedule this with cron to run daily (or more frequently) for automatic sync.
  • WordPress Plugin Workflow (User-Friendly)
    Plugins like WP All Import/Export let you export a dedicated XML feed of your Live site's attachments, then set up scheduled imports on Beta and Kiosk. This is great if you prefer a GUI over command-line tools, though it’s less performant for large media libraries.

2. Unified Media Library Data Source (No Database Sync Required)

If you want to avoid syncing databases entirely, modify your Beta and Kiosk sites to pull media metadata directly from the Live site’s database.

Add this snippet to your Beta/Kiosk wp-config.php (or a custom plugin):

// Route media library queries to the Live database
add_action('pre_get_posts', function($query) {
    // Only target admin media library queries
    if (is_admin() && $query->get('post_type') === 'attachment') {
        global $wpdb;
        // Replace with your Live database credentials
        $live_db = new wpdb(
            'live_db_user',
            'live_db_password',
            'live_db_name',
            'live_db_host'
        );
        $wpdb = $live_db;
    }
});

This makes Beta/Kiosk admins see the exact media library as Live, while still using their own databases for other content. Just ensure your Beta/Kiosk database users have read access to the Live database.

3. Optimize Your Shared Folder Setup

If you’re using a network mount (like NFS or SMB) for wp-content/uploads, double-check:

  • The mount is bidirectional (all sites can read/write to the folder) so new uploads from any site appear everywhere.
  • File permissions are consistent across servers (use chmod 755 for folders and 644 for files) to avoid WordPress permission errors.
Critical Best Practices
  • Centralize Uploads: Restrict media uploads to the Live site only. This eliminates sync conflicts and means you only need to push updates to Beta/Kiosk, not pull from them.
  • Fix Cross-Domain Links: Use the WordPress CLI to update URL references in metadata:
    wp search-replace 'https://live-domain.com/wp-content/uploads' 'https://kiosk-domain.com/wp-content/uploads' --skip-columns=guid
    
  • Test Syncs: Run manual syncs first to verify metadata and files align before setting up automation.

内容的提问来源于stack exchange,提问作者Keith Pickering

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:21:44