Modern websites often need scalable and reliable file storage solutions for images, videos, PDFs, and other assets. One of the best tools for this is Google Cloud Storage (GCS). In this article, we’ll show you how to integrate GCS with Drupal so that all your files are stored and served directly from Google’s cloud infrastructure.
Why Use Google Cloud Storage?
Google Cloud Storage offers:
- High availability and redundancy
- Seamless integration with CDN
- Flexible access control (public/private)
- Easy authentication via service accounts
⚠️ Important: To use Google Cloud, you must link a credit card to your Google Cloud Platform (GCP) account — even if you’re only using the free tier. Without this, the service cannot be activated.
Step 1: Create a Google Cloud Storage Bucket
- Go to the Google Cloud Console
- Click “Create bucket” and choose a name
- Select a region (e.g.,
europe-west1) and storage class (e.g.,Standard) - Set access permissions:
- For public files, enable “Uniform bucket-level access” and assign roles like
Storage Object Viewer - For private use, skip public access settings
- For public files, enable “Uniform bucket-level access” and assign roles like
Step 2: Create a Service Account and Get the Key
- Go to IAM & Admin → Service Accounts
- Click “Create Service Account”
- Assign the role: Storage Object Admin
- Create and download a JSON key
- Place the key securely on your server (e.g.,
/var/secrets/gcs-key.json)
Step 3: Install the Required Modules in Drupal
Drupal uses the Flysystem library to abstract remote file storage.
In your terminal, run:
composer require drupal/flysystem_gcs
Then enable the necessary modules:
drush en flysystem flysystem_gcs -y
Step 4: Configure GCS in settings.php
Add the following configuration to your settings.php file:
$settings['flysystem']['gcs_public'] = [
'driver' => 'gcs',
'config' => [
'bucket' => 'your-bucket-name',
'key_file_path' => '/var/secrets/gcs-key.json',
'prefix' => 'public', // Optional subfolder
],
];
// Set public:// to point to gcs_public://
$settings['file_public_scheme'] = 'gcs_public';
Replace
your-bucket-namewith your actual GCS bucket name.
Step 5: Clear the Cache and Test
Run:
drush cr
Upload a file (e.g., an image) via a content form and check if it appears in your Google Cloud Storage bucket.
Optional Enhancements
- CDN: Enable Cloud CDN to speed up delivery of your files.
- Signed URLs: Use time-limited URLs to control access to private files.
- Custom domain: Set up a CNAME like
cdn.yourdomain.comfor serving assets via your domain.
Conclusion
Integrating Google Cloud Storage with Drupal provides a robust and scalable solution for handling media assets. With the help of the flysystem_gcs module, you can redirect all your public file uploads to the cloud, easing server load and improving file delivery speeds.
💳 Reminder: A valid credit card is required to activate Google Cloud Platform services — including free-tier projects. This is a standard Google requirement for security and verification.
Need help setting this up for your site? Contact us — we’re happy to assist.
Comments