Listed below are the steps I took to use Ceph object store for WordPress media without a plugin. It works by mounting Ceph (or an AWS S3) bucket as a network device on the file system via s3fs and using wp-content/uploads/ as the mount path.
Since s3fs is POSIX compatible, it means you can still access (and manage) the media within wp-content/uploads/ over SFTP/SSH as if they are natively there.
WP-CLI commands such as wp media import and wp media regenerate also still work.
Although your media is being stored and fetched from a network storage bucket, your web server can still resolve all the requests to wp-content/uploads/ on the local filesystem like normal.
This means that image URLs do not have to be rewritten and will use the core format you're used to over HTTP https://mysite.com/wp-content/uploads/cat.jpg and any absolute filesystem paths in PHP that may exist /path/to/wp-content/uploads/cat.jpg.
- I used a standard WordPress 4.7.3 install on an Ubuntu 16.04.2 VPS running Apache 2.4.18 and PHP 7.1.3.
- Using a
s3fsmount isn't super fast. I noticed the most blantant lag when uploading image(s) to the Media Library. I had to wait what seemed like 60 seconds just for the thumbnail preview of one image to appear. - goofys is said to be 2-10x faster, but I haven't tried it (yet). It has less POSIX support.
- Install the
s3fsprogram:
sudo apt-get install s3fs- Save default credentials:
sudo echo MYACCESSKEY:MYSECRETKEY > /etc/passwd-s3fs
sudo chmod 600 /etc/passwd-s3fs- Uncomment the
user_allow_otherconfig infuse.conf:
sudo vi /etc/fuse.conf- Add a config to
/etc/fstabso your bucket will be mounted on boot:
sudo vi /etc/fstab- Change the bucketname, uploads path, and
urloption to fit your setup - For S3 buckets, remove the
use_path_request_styleandurloptions - The
uidandgidoptions are used to set the ownership ofwp-content/uploads/once it's mounted. Set these to match your$APACHE_RUN_USERand$APACHE_RUN_GROUPenvvars, respectively.
s3fs#bucketname /path/to/wp-content/uploads fuse _netdev,allow_other,use_path_request_style,no_check_certificate,mp_umask=022,uid=www-data,gid=www-data,url=https://storage.api.hostname.com 0 0
- Make sure
wp-content/uploads/is empty
rm -Rf /path/to/wp-content/uploads && mkdir /path/to/wp-content/uploads- Mount all file systems that are defined in
/etc/fstab:
sudo mount -aList all file system mounts:
sudo df -hUnmount the bucket from the file system:
sudo umount s3fs
I'm using S3Fs in production for 2 years. Its very stable. you can pass a local cache to s3fs. This will improve read a lot! The only problem with this aproach, do not owerwrite files , the cache versions will not update ad s3fs do not provide any way to invalidate cache.