If you are creating a new function, see the Console Quickstart on Cloud Run. The content on this page only applies to existing legacy functions created with the Cloud Functions v1 API.
Stay organized with collections
Save and categorize content based on your preferences.
The PHP Runtime
Your Cloud Run function runs in an environment consisting of an operating
system version plus add-on packages, language support, and
the Functions Framework library that supports and invokes your function.
This environment is identified by the language version, and is known as the
runtime.
These runtimes use nginx and PHP-FPM to serve requests. To learn more
about runtimes in general, and to learn which Ubuntu version each PHP runtime
uses, see the Cloud Run functions execution
environment.
Select your runtime
Cloud Run functions supports several versions of PHP, listed on the
Runtime support page. You can
select the preferred PHP runtime for your function during deployment.
gcloud
If you're using the Google Cloud CLI, specify the runtime
by using the --runtime parameter. NAME specifies the
function name. For example:
You can prepare a function directly from the Google Cloud console or write it on
your local machine and upload it. To prepare your local machine for PHP
development, see Using PHP on Google Cloud.
For Cloud Run functions to find your function's definition, your
source code must follow a specific structure. See
Writing Cloud Run functions
for more information.
PHP Configuration
You configure your PHP function with a php.ini
file in your function's
root directory. You can view existing PHP configuration settings with the
phpinfo() function as
shown 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
You specify dependencies for your function by adding them to a project file
called composer.json. For more information, see Specifying dependencies in
PHP.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-03 UTC."],[[["\u003cp\u003eCloud Run functions use \u003ccode\u003enginx\u003c/code\u003e and \u003ccode\u003ePHP-FPM\u003c/code\u003e to serve requests and run in an environment defined by the language version, known as the runtime.\u003c/p\u003e\n"],["\u003cp\u003eYou can select the preferred PHP runtime version for your function during deployment, with several versions supported and listed on the Runtime support page.\u003c/p\u003e\n"],["\u003cp\u003eFunctions can be deployed using the Google Cloud CLI with the \u003ccode\u003e--runtime\u003c/code\u003e parameter, or through the Google Cloud console.\u003c/p\u003e\n"],["\u003cp\u003ePHP functions can be prepared locally or directly in the Google Cloud console, and use the PHP Functions Framework library.\u003c/p\u003e\n"],["\u003cp\u003eDependencies for your PHP function are specified in a \u003ccode\u003ecomposer.json\u003c/code\u003e file, and configurations can be managed via a \u003ccode\u003ephp.ini\u003c/code\u003e file in the root directory.\u003c/p\u003e\n"]]],[],null,["# The PHP Runtime\n===============\n\nYour Cloud Run function runs in an environment consisting of an operating\nsystem version plus add-on packages, language support, and\nthe Functions Framework library that supports and invokes your function.\nThis environment is identified by the language version, and is known as the\nruntime.\n\nThese runtimes use `nginx` and `PHP-FPM` to serve requests. To learn more\nabout runtimes in general, and to learn which Ubuntu version each PHP runtime\nuses, see the [Cloud Run functions execution\nenvironment](/functions/1stgendocs/concepts/execution-environment#php).\n\nSelect your runtime\n-------------------\n\nCloud Run functions supports several versions of PHP, listed on the\n[Runtime support](/functions/1stgendocs/runtime-support#php) page. You can\nselect the preferred PHP runtime for your function during deployment. \n\n### gcloud\n\nIf you're using the Google Cloud CLI, specify the runtime\nby using the `--runtime` parameter. \u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e specifies the\nfunction name. For example: \n\n```bash\ngcloud functions deploy NAME --no-gen2 --runtime php82 --trigger-http\n```\n\nFor more deployment parameters, see [Deploy a Cloud Run function](/functions/1stgendocs/deploy#basics).\n\n### Console\n\nIf you're using the Google Cloud console, see the [Google Cloud console\nquickstart](/functions/1stgendocs/console-quickstart-1st-gen) for\ndetailed instructions.\n\nFunction preparation\n--------------------\n\nYou can prepare a function directly from the Google Cloud console or write it on\nyour local machine and upload it. To prepare your local machine for PHP\ndevelopment, see [Using PHP on Google Cloud](/php/docs).\n\nThe library that invokes your function is the [PHP Functions\nFramework](https://github.com/GoogleCloudPlatform/functions-framework-php).\n| **Note:** The only type of [event-driven functions](/functions/1stgendocs/writing#types_of_cloud_functions) PHP supports are [CloudEvent functions](/functions/1stgendocs/writing#cloudevent_functions).\n\nSource code structure\n---------------------\n\nFor Cloud Run functions to find your function's definition, your\nsource code must follow a specific structure. See\n[Writing Cloud Run functions](/functions/1stgendocs/writing#structuring_source_code)\nfor more information.\n\nPHP Configuration\n-----------------\n\nYou configure your PHP function with a [`php.ini`\nfile](https://www.php.net/manual/en/configuration.file.php) in your function's\nroot directory. You can view existing PHP configuration settings with the\n[`phpinfo()`](https://www.php.net/manual/en/function.phpinfo.php) function as\nshown in the following code sample: \n\n \n use Psr\\Http\\Message\\ServerRequestInterface;\n\n function phpInfoDemo(ServerRequestInterface $request): string\n {\n // phpinfo() displays its output directly in the function's\n // HTTP response, so we don't need to explicitly return it\n //\n // Note: we recommend deleting the deployed Cloud Function once you no\n // longer need it, as phpinfo() may broadcast potential security issues.\n phpinfo();\n return '';\n }\n\nSpecifying dependencies\n-----------------------\n\nYou specify dependencies for your function by adding them to a project file\ncalled `composer.json`. For more information, see [Specifying dependencies in\nPHP](/functions/1stgendocs/writing/specifying-dependencies-php)."]]