Hướng dẫn sử dụng
Plugin giúp đồng bộ media WordPress lên object storage — tiết kiệm dung lượng hosting, tối ưu băng thông, tích hợp CDN dễ dàng.
Cài đặt
Có 2 cách cài đặt plugin S3 Media Sync:
Cách 1: Clone từ GitHub (khuyến nghị)
# SSH vào server, vào thư mục plugins
cd wp-content/plugins/
git clone https://github.com/codetot-web/s3-media-sync.git
cd s3-media-sync
composer install --no-dev --optimize-autoloader
Cách 2: Download release ZIP
# Tải file ZIP từ GitHub Releases
wget https://github.com/codetot-web/s3-media-sync/releases/download/v1.0.1/s3-media-sync.zip
unzip s3-media-sync.zip -d wp-content/plugins/
Sau khi cài, vào WP Admin → Plugins → kích hoạt "S3 Media Sync".
Cấu hình cơ bản
- Vào Settings → S3 Media Sync
- Chọn Storage Provider: AWS S3 hoặc S3-Compatible
- Nhập Access Key, Secret Key, Bucket name
- Click Test Connection để kiểm tra
- Bật Enable Sync và chọn chế độ sync:
- Instant: Upload ngay lập tức — phù hợp media nhỏ
- Background: Hàng đợi WP-Cron 10 phút — phù hợp media lớn
- Save settings
Tính năng chính
Auto-sync
Tự động upload lên S3 khi thêm media vào WordPress. Hỗ trợ Instant + Background mode.
All image sizes
Upload original + tất cả resized variants. Chỉ xoá local khi tất cả sizes upload thành công.
URL Rewriting
Serve media từ S3/CDN. Rewrite qua WordPress filters: srcset, content, Yoast SEO, Elementor.
Delete sync
Xoá media trong WordPress → tự động xoá object trên S3. Gồm original + tất cả sizes.
Bulk sync
Sync toàn bộ media library cũ qua Tools page. Resumable — dừng và tiếp tục bất kỳ lúc nào.
Dọn local
Sau khi sync thành công, xoá local files để giải phóng dung lượng hosting.
Providers được hỗ trợ
Câu hỏi thường gặp
Plugin có xoá file gốc không?
Mặc định không. Bạn phải bật Delete local after upload trong Settings để xoá local sau khi sync.
Làm sao để serve media qua CDN?
Nhập CDN URL (vd: https://cdn.example.com) vào Public Bucket URL. Plugin tự động append bucket + file path.
Có support multisite không?
Có. Mỗi site trong network có thể dùng chung bucket hoặc riêng.
Hướng dẫn DevOps
Cấu hình server, deployment, automation và CLI dành cho team vận hành.
Requirements
- WordPress ≥ 5.8
- PHP ≥ 7.4
- Composer (để cài AWS SDK)
- WP-CLI (optional, khuyến nghị)
Deployment pipeline
Add vào deployment script của dự án:
#!/bin/bash # deploy-s3-media-sync.sh SITE_PATH=/var/www/example.com # Clone/update plugin if [ -d "$SITE_PATH/wp-content/plugins/s3-media-sync" ]; then cd "$SITE_PATH/wp-content/plugins/s3-media-sync" git pull origin master else git clone https://github.com/codetot-web/s3-media-sync.git "$SITE_PATH/wp-content/plugins/s3-media-sync" cd "$SITE_PATH/wp-content/plugins/s3-media-sync" fi composer install --no-dev --optimize-autoloader # Activate plugin (nếu chưa active) wp plugin activate s3-media-sync --path="$SITE_PATH" # Sync existing media wp s3 sync --batch=50 --path="$SITE_PATH"
Cấu hình S3-Compatible providers
| Provider | Endpoint | Region | Notes |
|---|---|---|---|
| AWS S3 | leave blank | ap-southeast-1 | Virtual-hosted URLs |
| Cloudflare R2 | https://<accountid>.r2.cloudflarestorage.com | auto | Path-style, zero egress |
| iDrive E2 | https://<B>.e2.idy.idrivee2.com | us-east-1 | Check iDrive docs |
| MinIO | https://minio.example.com | us-east-1 | Self-hosted |
| DigitalOcean Spaces | https://<region>.digitaloceanspaces.com | sgp1 | Path-style |
| Wasabi | https://s3.<region>.wasabisys.com | ap-northeast-1 | No egress fees |
Automation với CLI
Plugin CLI commands có thể dùng trong cron, CI/CD và deployment scripts:
# Cron: daily sync check lúc 3h sáng 0 3 * * * /usr/local/bin/wp s3 sync --batch=50 --path=/var/www/example.com # Post-deployment: verify connection wp s3 status # Reset và re-sync sau migration wp s3 reset wp s3 sync # Xoá local files sau khi xác nhận S3 OK wp s3 delete-local
Troubleshooting
Connection failed
Kiểm tra: credentials, bucket tồn tại, endpoint đúng, firewall không block outgoing.
Files không sync
Kiểm tra: "Enable Sync" được bật, AWS SDK installed, file tồn tại trên disk, WP-Cron hoạt động (nếu dùng Background mode).
URL không rewrite
Kiểm tra Public Bucket URL đã cấu hình đúng. Verify URL trỏ đến bucket và bucket public readable.
Marketing Toolkit
Tính năng, USP, messaging và tài liệu cho team Marketing.
Giới thiệu ngắn
S3 Media Sync là plugin WordPress mã nguồn mở (GPLv2) giúp đồng bộ toàn bộ thư viện media lên S3-compatible storage — AWS S3, iDrive E2, MinIO, Cloudflare R2, DigitalOcean Spaces. Plugin tự động upload khi thêm media, hỗ trợ bulk sync thủ công, URL rewriting qua CDN, và dọn file local sau sync.
USP (Unique Selling Points)
100% Mã nguồn mở
GPLv2. Không premium, không upsell, không tính năng khoá. Tất cả tính năng đều miễn phí.
Mọi S3-compatible provider
AWS S3, R2, iDrive E2, MinIO, DO Spaces, Wasabi, Backblaze B2 — không lock-in.
CLI-first design
Đầy đủ WP-CLI commands. Plugin được xây cho automation, không chỉ admin UI.
Bundled AWS SDK
AWS SDK for PHP bundled, vendor optimized chỉ ~4.4MB. Không cần cài thêm dependencies.
Background sync
Sync qua WP-Cron cho large library. Không timeout browser, không block user.
Security-first
PCP compliant, credentials sanitized, SSL verify, wp_delete_file(), prepared SQL statements.
Target audiences
| Audience | Pain point | Solution | Message |
|---|---|---|---|
| Web developers | Quản lý media trên nhiều server, migration tốn thời gian | Auto-sync, CLI, WP-Cron bg sync | "Set once, automate forever" |
| Agency owners | Dung lượng hosting tốn kém, cần CDN cho client | Offload media → object storage rẻ, CDN tích hợp | "Giảm 80% dung lượng hosting" |
| Site owners | Site chậm do media từ server gốc, không có CDN | URL rewriting → CDN, CloudFront, BunnyCDN | "Serve media global với 1 click" |
| DevOps engineers | Ephemeral hosting (Kinsta, Pantheon), mất media khi deploy | S3-backed persistent media | "Ephemeral? No problem." |
Competitor comparison
| Tính năng | S3 Media Sync | WP Offload Media | Media Cloud |
|---|---|---|---|
| Giá | Free (GPLv2) | $99+/năm | $49+/năm |
| Mã nguồn mở | ✅ | ❌ | ❌ |
| S3-Compatible providers | ✅ Tất cả | Limited | Limited |
| WP-CLI | ✅ Đầy đủ | ✅ Cơ bản | ❌ |
| Background sync | ✅ WP-Cron | ✅ | ❌ |
| Cache purge auto | ✅ 5 plugins | Limited | Limited |
| Activity Log | ✅ 500 events | ✅ | ❌ |
Content Plan & Use Cases
Ý tưởng bài viết, hướng dẫn, case study cho team Content.
Blog post ideas
Cách đồng bộ Media WordPress lên S3 với plugin miễn phí
Hướng dẫn từ A-Z: cài đặt, cấu hình AWS S3, kích hoạt sync.
S3 Media Sync vs WP Offload Media — Nên chọn cái nào?
So sánh tính năng, giá cả, hiệu năng. Kết luận: plugin free đủ dùng cho đa số.
Dùng MinIO + S3 Media Sync cho WordPress nội bộ
Hướng dẫn setup MinIO self-hosted + tích hợp với plugin.
Giảm 80% dung lượng hosting với offload media
Case study: site 10GB media, offload lên S3, chỉ còn 2GB local.
Automation WordPress: S3 Media Sync + WP-CLI + CI/CD
Pipeline: deploy code → sync media → purge cache, tất cả tự động.
Cloudflare R2: Zero egress fees cho media WordPress
Hướng dẫn dùng R2 làm object storage + CDN cho WordPress.
Use cases
1. Website tin tức / báo chí
Hàng nghìn hình ảnh mỗi tháng. Dùng S3 Media Sync + CDN (CloudFront) để serve ảnh global. Tiết kiệm băng thông server gốc, giảm TTFB.
2. Thương mại điện tử (WooCommerce)
Hàng trăm ảnh sản phẩm, mỗi ảnh nhiều kích thước. Offload lên S3 giúp giảm dung lượng hosting, tăng tốc product page.
3. Multisite network
5-50 sites chia sẻ media bucket. Plugin support multisite, mỗi site có thể có bucket riêng hoặc prefix riêng.
4. Agency hosting nhiều client
Mỗi client một bucket riêng. Dùng WP-CLI automation thiết lập cho site mới: clone plugin → activate → config → sync.
5. Ephemeral hosting (Kinsta, Pantheon)
Server tạm, mất file upload khi deploy. S3 Media Sync đảm bảo media persistent qua mọi deployment.
Social media posts
📱 Thread (X/Twitter) — Tính năng:
🧵 S3 Media Sync là gì?
1/ Plugin WordPress miễn phí, mã nguồn mở (GPLv2)
2/ Đồng bộ media lên AWS S3, Cloudflare R2, MinIO, iDrive E2...
3/ URL rewriting + CDN, dọn local, WP-CLI
4/ Background sync, delete sync, activity log
5/ Thay thế WP Offload Media ($99/năm) — hoàn toàn free 🆓
📘 LinkedIn — DevOps góc nhìn:
You deploy WordPress. Media lives on server. Server runs out of disk. Again.
S3 Media Sync fixes this. One plugin. Free. GPLv2.
6 CLI commands. 5 cache plugins auto-purge. 10+ S3 providers.
Built by CODE TOT for production WordPress.
👉 github.com/codetot-web/s3-media-sync
CLI Reference
Tài liệu đầy đủ về WP-CLI commands của S3 Media Sync. Yêu cầu WP-CLI.
| Command | Description | Requires |
|---|---|---|
wp s3 sync | Sync all unsynced attachments to S3 | Plugin enabled + configured |
wp s3 sync --post_id=<id> | Sync a single attachment by ID | — |
wp s3 sync --batch=<n> | Custom batch size (default: 10, max: 100) | — |
wp s3 status | Check S3 connection + config summary | Plugin configured |
wp s3 delete-local | Delete local files of synced media | Media already synced |
wp s3 reset | Reset all sync status metadata | — |
wp s3 sync
CORE — Process all unsynced attachments and upload to S3.
OPTIONS
| Option | Type | Default | Description |
|---|---|---|---|
--post_id=<id> | int | — | Sync a single attachment by ID |
--batch=<n> | int | 10 | Number of attachments to process per batch (1–100) |
EXAMPLES
# Sync all unsynced attachments $ wp s3 sync Syncing 1500 attachments 100% ████████████████████████████████ Success: Sync complete. Synced: 1423, Errors: 2 # Sync single attachment $ wp s3 sync --post_id=42 Success: Synced ID 42 to bucket "my-bucket" # Process 50 attachments per batch (faster for large libraries) $ wp s3 sync --batch=50
wp s3 status
DIAGNOSTICS — Check plugin configuration and S3 connection.
EXAMPLES
$ wp s3 status Status: Enabled Provider: s3-compatible Bucket: my-media-bucket Region: ap-southeast-1 Endpoint: https://s3.ap-southeast-1.idy.idrivee2.com Success: S3 connection: OK (bucket accessible)
wp s3 delete-local
DESTRUCTIVE — Remove local file copies for attachments that have been synced. Only affects files with s3_media_sync_synced meta. Original + all resized sizes are deleted.
NOTES
- Only processes attachments with
s3_media_sync_syncedmeta - Skips files already marked with
s3_media_sync_local_removed - Deletes original file + all sizes from
wp_get_attachment_metadata()
EXAMPLES
# Delete local files for all synced attachments $ wp s3 delete-local Success: Deleted local files for 850 attachments. # Verify: files should now be served from S3/CDN $ wp s3 status Success: S3 connection: OK (bucket accessible)
wp s3 reset
DESTRUCTIVE — Clear all sync status metadata. After reset, all attachments are treated as "not synced" and can be re-synced from scratch.
NOTES
- Deletes
s3_media_sync_syncedmeta from all posts - Deletes
s3_media_sync_local_removedmeta from all posts - Does NOT delete files from S3
- Does NOT delete local files
EXAMPLES
# Reset then re-sync all media
$ wp s3 reset
Success: Reset complete. Cleared 1423 synced marks and 850 local removal marks.
$ wp s3 sync --batch=50
Syncing 1500 attachments
Success: Sync complete. Synced: 1500, Errors: 0
Best practices
🔄 Deployment flow
git pull → composer install → wp s3 sync → wp cache flush
⏰ Nightly cron
0 3 * * * wp s3 sync --batch=50 >/dev/null 2>&1
🧪 Pre-deployment check
wp s3 status && wp s3 sync --dry-run (future)