Introduction
Zero CMS features a highly optimized, fully integrated, and 100% zero-dependency Google Cloud Storage (GCS) driver. This custom driver bypasses heavy external SDKs entirely, executing secure OAuth 2.0 JWT exchanges via native PHP OpenSSL and file uploads via raw PHP cURL sessions directly for maximum execution speed, footprint reduction, and supply-chain protection.
Step 1: Obtain Google Service Account Key JSON
To authorize REST API requests with Google, you must obtain a Service Account Key file from your Google Cloud Console:
- Navigate to **IAM & Admin > Service Accounts** in the GCP Console.
- Create a service account and assign it the **Storage Admin** role (or full storage control).
- Click on the newly created service account, navigate to the **Keys** tab, and select **Add Key > Create New Key**.
- Choose the **JSON** format, click **Create**, and save the downloaded file securely onto your server disk (e.g. at
/data/misc/zero/etc/gcp-key.json, keeping it outside the public web root).
Step 2: Configure Environment Variables (.env)
Open your local environmental configuration file (.env) and update your storage credentials. Our zero-dependency driver supports both GCP bucket access models seamlessly:
- Uniform Bucket-Level Access (Recommended): Keeps security centrally managed at the bucket level. To make files public, grant the Storage Object Viewer (
roles/storage.objectViewer) role to the memberallUserscentrally in your GCP Console, and leaveGCS_PREDEFINED_ACLempty or commented out inside your.env. - Fine-Grained (ACL-based) Access: Manage access per file. Turn Uniform access OFF centrally in GCP, and define
GCS_PREDEFINED_ACL=publicReadinside your.env. Our custom driver will automatically append public-read permissions to every uploaded asset dynamically.
# Set active storage driver to GCS
STORAGE_DRIVER=gcs
# Define target Google Cloud Bucket name
GCS_BUCKET_NAME=your_gcs_bucket_name_here
# Define Google Cloud Project ID
GCS_PROJECT_ID=your_gcp_project_id_here
# Define the absolute physical path to your service account key file
GCS_KEY_FILE=/data/misc/zero/etc/gcp-key.json
# Optional: Define predefined ACL (use 'publicRead' for Fine-Grained buckets, leave empty for Uniform buckets)
GCS_PREDEFINED_ACL=publicReadStep 3: Utilizing the Storage API
Once configured, the core CMS will automatically route all file storage, media uploads, and crops through your zero-dependency GCS driver. You can also invoke the static Storage API helper from anywhere in your custom modules:
use Zero\Core\Storage\Storage;
// 1. Upload a file
Storage::putFile('uploads/avatars/user-123.jpg', '/tmp/avatar.jpg');
// 2. Check if file exists in the cloud bucket
if (Storage::exists('uploads/avatars/user-123.jpg')) {
// 3. Resolve the public GCS public URL
$url = Storage::getUrl('uploads/avatars/user-123.jpg');
// Returns: https://storage.googleapis.com/your-bucket/uploads/avatars/user-123.jpg
}