Skip to content

Instantly share code, notes, and snippets.

@hluker
Last active October 13, 2022 01:40
Show Gist options
  • Select an option

  • Save hluker/d9fbcd4fe0a489f83e562feae6e59733 to your computer and use it in GitHub Desktop.

Select an option

Save hluker/d9fbcd4fe0a489f83e562feae6e59733 to your computer and use it in GitHub Desktop.
Google Cloud Storage and WordPress

We're assuming here that both your Storage bucket and virtual machine are BOTH hosted in GCP

Make sure that your uploads directory is EMPTY

You can usually change the owner of the folder to root to prevent WordPress's pesky folder creation

create a cloud bucket

  1. Visit Google Cloud Storage
  2. Create bucket
  3. Name your bucket: similar to website name (i.e. "google" for google.com)
  4. Choose where to store your data: region, usually
  5. Choose a default storage class for your data: standard
  6. Choose how to control access to objects: uniform
  7. Go to Permissions
  8. Add Members -> give access to Storage Object Viewer, Storage Legacy Object Reader, Storage Legacy Bucket Reader

now onto your VM...

Make sure that your VM has Read/Write access for the Storage cloud API scope

export GCSFUSE_REPO=gcsfuse-`lsb_release -c -s`
echo "deb http://packages.cloud.google.com/apt $GCSFUSE_REPO main" | sudo tee
/etc/apt/sources.list.d/gcsfuse.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install gcsfuse

Then, edit fuse.conf -- uncomment "user_allow_other" and save

let's mount the thing

cd /var/www/example.com/public_html/wp-content/
chmod a+w uploads
gcsfuse --dir-mode "777" -o allow_other BUCKET_NAME_HERE uploads

auto mount

in your /etc/fstab. be careful with this!

BUCKET_NAME_HERE /var/www/example.com/public_html/wp-content/uploads gcsfuse rw,allow_other,dir_mode=777,_netdev

you can test using this

fusermount -zu uploads
mount uploads

if you encounter issues, well..... fix them]

@w3s-admin

Copy link
Copy Markdown

thank you so much you save the day......

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment