PHP ON GOOGLE CLOUD PLATFORM

View Documentation

PHP tools to build cloud-native apps, deploy at scale, and analyze data

  • Build scalable web apps and APIs
  • Access fully-managed MySQL, NoSQL, or PostgreSQL databases
  • Use Google’s machine learning APIs with native library support
  • Run containerized applications at scale
  • Deploy your favorite framework or CMS
lovingly-crafted composer packages

Take advantage of our APIs and services using the Google Cloud Composer packages and test run our code samples.

1
Install
$ composer require google/cloud-storage
2
Set up a Google Cloud Platform project
  1. In the Cloud Console, on the project selector page, select or create a Cloud project.

    Go to the project selector page

  2. Make sure that billing is enabled for your Google Cloud project. Learn how to confirm billing is enabled for your project.

  3. Enable the Cloud Storage API.

    Enable the API

3
Write your code
use Google\Cloud\Storage\StorageClient;

/**
 * Upload a file.
 *
 * @param string $bucketName the name of your Google Cloud bucket.
 * @param string $objectName the name of the object.
 * @param string $source the path to the file to upload.
 *
 * @return Psr\Http\Message\StreamInterface
 */
function upload_object($bucketName, $objectName, $source)
{
    $storage = new StorageClient();
    $file = fopen($source, 'r');
    $bucket = $storage->bucket($bucketName);
    $object = $bucket->upload($file, [
        'name' => $objectName
    ]);
    printf('Uploaded %s to gs://%s/%s' . PHP_EOL, basename($source), $bucketName, $objectName);
}
PHP QUICK STARTS
Quickly find and Debug issues

Google Stackdriver provides powerful monitoring, logging, and diagnostics. It equips you with insight into the health, performance, and availability of cloud-powered applications, enabling you to find and fix issues faster.

Play 'Google Stackdriver' video
Google Stackdriver
Unified monitoring, logging, and diagnostics for applications on Google Cloud Platform and AWS.
Play 'Stackdriver Error Reporting' video
Stackdriver Error Reporting
A walk through of getting an error alert and investigating the error in the Google Cloud Console.
Play 'Stackdriver Monitor, diagnose, and fix' video
Stackdriver Monitor, diagnose, and fix
In this video, Aja Hammerly uses Stackdriver to find and fix some subtle errors in an example app, and you'll learn how to use Stackdriver on your own projects.
Learn more
PHP ON GCP COMMUNITIES

Got something to say? Join our community to ask questions, or just chat with the experts at Google who help build PHP for Google Cloud Platform.