Skip to main content
Home
Drupal life hacks

Main navigation

  • Drupal
  • React
  • WP
  • Contact
  • About
User account menu
  • Log in

Breadcrumb

  1. Home

How to Integrate Google Cloud Storage with Drupal: Step-by-Step Guide

By admin, 11 July, 2025

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

  1. Go to the Google Cloud Console
  2. Click “Create bucket” and choose a name
  3. Select a region (e.g., europe-west1) and storage class (e.g., Standard)
  4. 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

Step 2: Create a Service Account and Get the Key

  1. Go to IAM & Admin → Service Accounts
  2. Click “Create Service Account”
  3. Assign the role: Storage Object Admin
  4. Create and download a JSON key
  5. 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-name with 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.com for 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.

Tags

  • #Drupal Planet
  • Google Cloud Platform

Comments

About text formats

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Powered by Drupal