The PHP Runtime

Cloud Functions supports the PHP 7.4 runtime.

For instructions on how to prepare your local machine for PHP development, see Using PHP on Google Cloud.

To get started with PHP on Cloud Functions, see the Quickstart.

Execution environment

The execution environment includes the PHP 7.4 runtime, the operating system, an application server, and a library that invokes your function.

The PHP 7.4 runtime uses an execution environment based on Ubuntu 18.04 using nginx and PHP-FPM. See Cloud Functions Execution Environment for more information.

The library that invokes your function is the PHP Functions Framework.

PHP Configuration

For a comprehensive look at the PHP configuration, you can deploy a function running phpinfo(), for example:


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 '';
}

Read up on the PHP 7 Runtime for information on enabled and dynamically loadable extensions.

Selecting the runtime

You can select the PHP runtime for your function during deployment.

gcloud

If you are using the gcloud command-line tool, you can specify the runtime by using the --runtime parameter. NAME specifies the function name. For example:

gcloud functions deploy NAME --runtime php74 --trigger-http

For more arguments that you can specify when you are deploying, see Deploy using the gcloud tool.

Console

If you are using the Cloud Console, you can select the runtime when you create and deploy a function. See the Cloud Console quickstart for detailed instructions.

Execution environment

The execution environment includes the runtime, the operating system, and a library that invokes your function. The runtime supports PHP 7.4.

The PHP runtime uses an execution environment based on Ubuntu 18.04. See Cloud Functions Execution Environment for more information.

The library that invokes your function is the PHP Functions Framework.

Source code structure

In order for Cloud Functions to find your function's definition, each runtime has certain structuring requirements for your source code. See Writing Cloud Functions for more information.

Specifying dependencies

You can specify dependencies for your function by adding them to a project file called composer.json. For more information, see Specifying dependencies in PHP.

What's next