How to integrate Google Cloud Storage with Laravel

July 7, 2025 · 4 min read

In this post, we'll walk you through integrating Google Cloud Storage (GCS) into your Laravel application, enabling you to upload, store, and serve files at scale. Whether you're building media-rich applications or need reliable, scalable cloud storage, this step-by-step guide will help you set up everything, from Google Cloud Storage configuration to Laravel usage. We will use the popular Spatie Google Cloud Storage package.
Using Google Cloud Storage with Laravel
Google Cloud Storage is reliable, scalable, and provides a robust solution for storing and accessing data. We recently used it for a project and decided to document the process in a blog post. Let's start by setting up our Google Cloud Platform environment.
Configuring Google Cloud Storage

Step 1. Create a New Project

Navigate to the GCP dashboard.
Click on "Select a Project" at the top and then "New Project".
Choose a meaningful project name related to your app to avoid confusion if managing multiple projects. (e.g., 'filament-cloud-project').
After creation, select the new project. This ensures all subsequent actions are applied to the right context.
Step 2. Create a GCS Service Account

Once the project is set up, it's time to create a service account. You can create different service accounts for different environments.
Go to Google Cloud Console > IAM & Admin > Service Accounts.
Click “Create Service Account.”
Give it a memorable name (e.g., 'filament-project-cloud-service').
Click “Create and Continue.”
Assign Roles to the Service Account
- Assign roles: Owner, Storage Admin, Storage Object Admin, and Storage Folder Admin. This gives the service account the right permissions to manage the storage needs.
Grant Access
- Add principals who need to perform actions using this account. This could be other team members or applications.

Step 3. Create a GCS Bucket

Buckets are the storage containers of GCS. You can make buckets public (when serving public files like images) or keep them private (recommended). If private, you can generate signed URLs in Laravel to grant temporary access. For simplicity, we will create a public bucket.
Go to Cloud Storage > Buckets.
Click "Create Bucket". Choose a globally unique name (e.g., 'filament-cloud-bucket').
Configure the Bucket.
Region: Choose based on location/performance needs.
Default Storage Class: Set it to "Standard."
Access Control: Uncheck "Enforce public access prevention on this bucket."

Step 4. Generate a JSON Key for the Service Account

Laravel uses this key to authenticate API requests to Google Cloud Storage.
Back in the Service Account, open the Keys tab.
Choose "Add Key > Create New Key".
Choose JSON and download the key.
Move this JSON file to the Laravel project root folder.
Setting Up Laravel for Google Cloud Storage
Now, let’s get our Laravel environment communicating with GCS.
Step 1. Install the Spatie Google Cloud Storage Package
Run the following composer command to install the Spatie Google Cloud Storage package:
composer require spatie/laravel-google-cloud-storageStep 2. Configure the Filesystem
Open config/filesystems.php and add a new disk configuration in the disks array:
'gcs' => [
'driver' => 'gcs',
'key_file_path' => base_path(env('GOOGLE_CLOUD_KEY_FILE', 'your-json-file.json')),
'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'),
'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET', 'your-bucket-id'),
'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', ''),
'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null),
'apiEndpoint' => env('GOOGLE_CLOUD_STORAGE_API_ENDPOINT', null),
'visibility' => 'public',
'visibility_handler' => \League\Flysystem\GoogleCloudStorage\UniformBucketLevelAccessVisibility::class,
'metadata' => ['cacheControl'=> 'public,max-age=86400'],
]Step 3. Add Environment variables
Update the .env file with the following:
GOOGLE_CLOUD_PROJECT_ID=your_project_id
GOOGLE_CLOUD_STORAGE_BUCKET=your_bucket_id
GOOGLE_CLOUD_KEY_FILE=your_json_file_name.jsonFile Management with Laravel and Google Cloud Storage
With everything set up, you can upload and download files using Laravel’s Storage facade. Here’s how:
Uploading files to Google Cloud Storage with Laravel
We can now easily download files from Google Cloud Storage with the Laravel Storage facade:
Storage::disk('gcs')->put('folder/file.txt', 'Contents here...');Downloading files to Google Cloud Storage with Laravel
Downloading files from Google Cloud Storage can also be done with the Laravel Storage facade:
Storage::disk('gcs')->download('folder/file.txt');Conclusion
In this article, we have integrated Google Cloud Storage into a Laravel application using FilamentPHP. We've built a scalable, reliable solution for managing files. Whether you're building the next big app or just tinkering around, Google Cloud Storage provides a great solution for your storage needs.
Bring Your Ideas to Life 🚀
If you need help with a Laravel project let’s get in touch.
Lucky Media is proud to be recognized as a leading Laravel Development Agency
FAQs
Why should I use Google Cloud Storage over other cloud storage services?
Google Cloud Storage offers a robust, scalable, and cost-effective solution with seamless integration into the Google Cloud ecosystem, making it a great choice for developers already using other Google services.
What are the benefits of using Google Cloud Storage with Laravel?
Using Google Cloud Storage with Laravel offers benefits such as scalability, reliability, and easy integration with other Google Cloud services. It also provides robust security features and global access to your data.
What are the costs associated with Google Cloud Storage?
Google Cloud Storage pricing varies based on storage class, data location, and operations performed. It's best to check Google's pricing page for the most current information.
How secure is Google Cloud Storage?
Google Cloud Storage provides robust security features, including encryption at rest and in transit, access control policies, and more, ensuring your data is well-protected.
Can I use Google Cloud Storage for storing large files?
Yes, Google Cloud Storage is ideal for storing large files due to its scalability and high availability. You can easily manage large datasets without worrying about storage limitations.
How can I keep my GCS files private while still providing access to users?
Use signed (temporary) URLs generated by Laravel’s Storage::disk('gcs')->temporaryUrl() method. These URLs grant time-limited access without making your bucket public.
Technologies

Stay up-to-date
Be updated with all news, products and tips we share!
On this page
- Using Google Cloud Storage with Laravel
- Configuring Google Cloud Storage
- Step 1. Create a New Project
- Step 2. Create a GCS Service Account
- Step 3. Create a GCS Bucket
- Step 4. Generate a JSON Key for the Service Account
- Setting Up Laravel for Google Cloud Storage
- Step 1. Install the Spatie Google Cloud Storage Package
- Step 2. Configure the Filesystem
- Step 3. Add Environment variables
- File Management with Laravel and Google Cloud Storage
- Uploading files to Google Cloud Storage with Laravel
- Downloading files to Google Cloud Storage with Laravel
- Conclusion
- Bring Your Ideas to Life 🚀
- FAQs

