Adding Digital Ocean Volume for WordPress Media can be very useful. Especially if you have a lot of images and or other media and need a cheap way to store them. Block Storage at Digital Ocean is fast and easy to work with. It allows you to get a cheap Droplet and add cheap storage.
We already wrote about Setting up Trellis on Digital Ocean. Now you can expand upon this with a volume for your media!
Format the Volume
To format the volume I followed Digital Ocean’s instructions. These you will get once a volume has been setup. In a popup you will get the line needed for your volume in your region. Idid a
sudo mkfs.ext4 -F /dev/disk/by-id/scsi-0DO_Volume_volume-lon1-01
Add directory to store media
If you have this WordPress setup from scratch and just start a website you can skip this as the media directory is yours to use
If you do not already have the media directory where you store the media you can create one. Most likely you do. We however moved the old sites one inside the wp-content/uploads for our multisite media to a backup location and then recreated it using:
sudo mkdir -p sites
This as we would later sync all that data from the production server.
Mounting the Volume
Next we had to mount that directory so that it would load all the data from the volume instead of the actual Droplet. We did that using:
sudo mount -o discard,defaults /dev/disk/by-id/scsi-0DO_Volume_volume-lon1-01 /srv/www/staging.domain.com/shared/uploads/sites;
And to make the mount permanent do a:
echo /dev/disk/by-id/scsi-0DO_Volume_volume-lon1-01 /srv/www/staging.domain.com/shared/uploads/sites ext4 defaults,nofail,discard 0 0 | sudo tee -a /etc/fstab
Then we checked if the mounting was successful:
cat /proc/mounts |grep staging /dev/sda /srv/www/staging.domain.com/shared/uploads/sites ext4 rw,relatime,discard,data=ordered 0 0
As you see it was. And this means for most of you that you are done. You will have a Digital Ocean Volume for WordPress Media. We however needed to get the media copied over still.
If you have this setup from scratch and just start a website you can skip this
Normally if you have a media volume already and need one for staging or another clone of the server you can just clone the volume and set up a new one and attach it. We only had an issue as the production server and volume were in a different region than staging so we had to set up a volume from scratch at both locations and sync the data between them:
ssh -o ForwardAgent=yes email@example.com "rsync -aze 'ssh -o StrictHostKeyChecking=no' --progress /srv/www/domain.com/current/web/app/uploads/sites/ firstname.lastname@example.org:/srv/www/staging.domain.com/shared/uploads/sites/"