The PHP runtime

Your Cloud Run function runs in an environment consisting of anoperating system version with add-on packages, language support, andthePHP Functions Frameworklibrary that supports and invokes your function. This environment is identifiedby the language version, and is known as the runtime ID.

Function preparation

You can prepare a function directly from the Google Cloud console or write it onyour local machine and upload it. To prepare your local machine for PHPdevelopment, seeUse PHP on Google Cloud.

Supported PHP runtimes and base images

RuntimeRuntime IDStacksRuntime base image
PHP 8.5
(Preview)
php85 google-24-full (default)google-24-full/php85
PHP 8.4php84 google-22-full (default)google-22-full/php84
PHP 8.3php83 google-22-full (default)google-22-full/php83
PHP 8.2php82 google-22-full (default)google-22-full/php82
PHP 8.1php81 google-18-fullgoogle-18-full/php81
PHP 7.4php74 google-18-fullgoogle-18-full/php74

Select your runtime

You can select one of the supported PHP runtimes for your function duringdeployment.

You can select a runtime version using the Google Cloud console, or thegcloud CLI. Click the tab for instructions on using the tool ofyour choice:

gcloud

Specify thePHP base image for your function using the--base-image flag,while deploying your function. For example:

gcloud run deployFUNCTION \    --source . \    --functionFUNCTION_ENTRYPOINT \    --base-image php84

Replace:

  • FUNCTION with the name of the function you aredeploying. You can omit this parameter entirely,but you will be prompted for the name if you omit it.

  • FUNCTION_ENTRYPOINT with the entry point to your function inyour source code. This is the code Cloud Run executes when yourfunction runs. The value of this flag must be a function name orfully-qualified class name that exists in your source code.

For detailed instructions on deploying a function using the gcloud CLI, seeDeploy functions in Cloud Run.

Console

You can select a runtime version when you create or update a Cloud Run function in the Google Cloud console. For detailedinstructions on deploying a function, seeDeploy functions in Cloud Run.

To select a runtime in the Google Cloud console when you create a function, follow these steps:

  1. In the Google Cloud console, go to the Cloud Run page:

    Go to Cloud Run

  2. ClickWrite a function.

  3. In theRuntime list, select a PHP runtime version.

  4. ClickCreate, and wait for Cloud Run to create the serviceusing a placeholder revision.

  5. The console will redirect you to theSourcetab where you can see the source code of your function. ClickSave and redeploy.

For detailed instructions on updating the runtime version after your function isdeployed, seeRe-deploy new source code.

Source code structure

For Cloud Run functions to find your function's definition, yoursource code must follow a specific structure. SeeWrite Cloud Run functions formore information.

PHP Configuration

You configure your PHP function with aphp.inifile in your function'sroot directory. You can view existing PHP configuration settings with thephpinfo() function asshown in the following code sample:

use Psr\Http\Message\ServerRequestInterface;function phpInfoDemo(ServerRequestInterface $request): string{    // phpinfo() displays its output directly in the function's    // HTTP response, so we don't need to explicitly return it    //    // Note: we recommend deleting the deployed Cloud Function once you no    // longer need it, as phpinfo() may broadcast potential security issues.    phpinfo();    return '';}

Specifying dependencies

PHP uses Composer to manage dependencies. You specify dependencies for yourfunction by adding the dependencies to a project file calledcomposer.json.

The Cloud Run functions PHP runtime requires the FunctionsFramework to be an explicit dependency. To add Functions Framework as adependency, run the following command in the directory containing your functioncode (this directory must also contain thecomposer.json file):

composer require google/cloud-functions-framework

This adds the Functions Framework to yourcomposer.json and installs thepackage in thevendor/ directory.

autoload.php file

One of the files contained in yourvendor/ directory isautoload.php.

Add the following line to the top of your PHP scripts to require theautoload.php file, which automaticallyrequires your function's otherdependencies:

require_once __DIR__ . '/vendor/autoload.php';

By default, thevendor/ directory is ignored in the generated.gcloudignore file to reduce thenumber of files sent in deployment.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.