Google Cloud Storage Quick Start Guide
This guide aims to help you start offloading your WordPress Media Library to a Google Cloud Storage bucket with WP Offload Media as quickly as possible.
We also have Quick Start Guides for other storage providers.
This article covers the following steps:
- Login to the GCP Console
- Create a Service Account Key File for GCS
- Saving the Service Account Key File details for WP Offload Media to use
- Activate Your WP Offload Media License
- Configure WP Offload Media to offload newly uploaded media to a Google Cloud Storage bucket
- Offload Your Existing Media Library
- Next steps for setting up WP Offload Media to use a CDN
Login to the GCP Console
Whether you already have a Google Cloud Platform (GCP) account or not, you can sign in or sign up from the Console home page.
Create Service Account Key File
Once you have logged into the console, you will need to create a new Service Account Key and save its file.
Navigate to the Credentials section of the APIs & Services page in the GCP Console for your selected project, click the Create credentials button and select Service account.
Now enter a name for the account and click Create and continue.
Click the Select a role dropdown. Then select “Cloud Storage” under By product or service, and select “Storage Admin”. The Storage Admin role will enable WP Offload Media to create buckets for you as well as manage objects in the bucket.
From the Credentials page, click the newly created service account at the bottom.
Click Keys, then the Add Key dropdown to select Create new key.
Leave the default Key type of JSON selected, then click the Create button to finish creating the new service account key and download its key file.
Define Your Key File Path
Now that you have your GCP Key File, you need to copy it to your WordPress site’s server so that WP Offload Media can use it when talking to the GCS service.
For better security, we recommend defining your access keys in your
define( 'AS3CF_SETTINGS', serialize( array( 'provider' => 'gcp', 'key-file-path' => '/path/to/key/file.json', ) ) );
IMPORTANT: Make sure to replace the “/path/to/key/file.json” string in the above example with the full path to the file on the server, it must be an absolute file path and must be accessible by the web server process that PHP is executed under. For security, do not store the file within the site’s own directory hierarchy where it could be downloaded by anyone.
These should be placed before the following comment in your
/* That's all, stop editing! Happy publishing. */
Warning: If you put the define after this comment, WP Offload Media will not be able to read its settings early enough to be useful and much weirdness will ensue!
Alternatively, you can enter the contents of your key file into the form on the Storage Provider page inside WP Offload Media, the first page shown when no keys are defined. This will save the credentials to the database, which is less secure than defining them in your
If you’re running your site on a Google Compute Engine (GCE) instance, you might like to use an IAM Role instead. This is even more secure than defining your access credentials in
Configure WP Offload Media
To start offloading newly uploaded media to Google Cloud Storage you need to first tell WP Offload Media which bucket it should use. If you have not already created a bucket to use with WP Offload Media, it can be created for you from WP Offload Media’s.
If you have already created the bucket you want to offload your media to, then you can enter the bucket name in the above input and click the Save Bucket button.
If you haven’t created the bucket yet, then you can click the Create new bucket link to get a form where you can specify the new bucket’s name and region.
You can also Browse existing buckets and select the one you want to use.
IMPORTANT: If you create or update a bucket via the Google Cloud Platform Console do not enable “Uniform bucket-level access” as this will stop WP Offload Media from managing the ACLs for objects.
Regardless of how you specify the bucket, once saved, WP Offload Media will be set up to offload newly-uploaded media to the bucket with some recommended default settings.
Make Sure Cron Is Set Up
We highly recommend that you configure a proper cron job on your server as WP Offload Media relies heavily on background processing. See our Cron Setup doc for details on how to accomplish this.
Activate Your WP Offload Media License
Now’s a good time to activate your WP Offload Media license so that (once configured) you can instantly take advantage of all its goodies.
Go to WP Offload Media’s settings page in the WordPress admin dashboard, found under the Settings menu.
Then click on the License tab, enter your license key in the input box, and click the Activate License button.
Offload Your Existing Media Library
Now that your site is configured to offload newly-uploaded media to Google Cloud Storage, you might want to offload any existing media to the bucket too.
In the right-hand sidebar of WP Offload Media’s Media Library tab you should see what we call the Offload Tool, this can be used to offload existing media to the bucket.
If you have not offloaded anything yet, then you’ll see a Your Media Library needs to be offloaded message in the Offload Tool with an Offload Now button.
If you have already offloaded a few items, then you might see a message like “66% of your Media Library has been offloaded” in the Offload Tool, with an Offload Remaining Now button.
Either way, clicking the Offload Tool’s button will start an upload to the bucket of all existing media yet to be offloaded.
The media offload progresses in small batches in the background to keep things efficient. You can close the tab and just forget about it, when the tool finishes its job, you’ll get a notice in the WordPress dashboard, or you can monitor progress from WP Offload Media’s settings page.
Once complete, the Offload Tool displays a “100% of your Media Library has been offloaded, congratulations!” message and the Download all files from bucket to server and Remove all files from bucket tools are made available.
Next Steps: Using a Content Delivery Network (CDN)
Now that your media is offloaded to Google Cloud Storage, your next step if you’re concerned about performance (i.e. load time and SEO), is to configure a Content Delivery Network (CDN).
By default WP Offload Media is configured to use raw Google Cloud Storage URLs when serving offloaded media. Your media URLs might look something like this:
Not only is this an ugly URL, but this URL is also bad for SEO as Google likes to see your media on your own domain. Also, Google Cloud Storage is primarily a storage platform and is not optimized for high speed delivery of media unless you are using a “Multi-Regional” bucket with built in CDN. Faster media is obviously better for user experience but also better for SEO. For these reasons, we strongly recommend configuring a Google Cloud CDN or another CDN for delivering your media. For more details about the benefits of Google Cloud CDN and other CDNs, please read our Why Use a CDN? doc.
We have a guide for How to Set Up a Custom Domain CDN for Google Cloud Storage.