The PHP runtime

Note: SomePHP runtimes have reachedend of support. You cannot re-deployversions that use runtimes after their end of support date. We recommend thatyouupgrade your appto use the latest version of PHP.

The PHP runtime is the software stack responsible forinstalling your application code and dependencies, and then running thatapplication in the flexible environment.

PHP versions

PHP 8.4 usesbuildpacks. For the full list of supportedPHP versions, and their corresponding Ubuntuversion, see theRuntime support schedule.

To use a supported PHP version, you must:

  • Installgcloud CLI version420.0.0 or later. You can update yourCLI tooling by running thegcloud components updatecommand. To view your installed version, you can run thegcloud version command.

  • Include theruntime_config andoperating_system settings in yourapp.yaml fileto specify an operating system.

  • Declare the document root for your application in theapp.yaml file:

    runtime:phpenv:flexruntime_config:operating_system:"ubuntu22"document_root:"web"

    Although you can specify the project root (.) directory as thedocument root, we recommend that you use a subdirectory for thedocument_root setting.

    The source code is located in the/workspacedirectory instead of the root directory (/). If you override any configuration,theNGINX orsupervisor processes reference your configuration file in this directory. Toupdate corresponding references, you must:

    • Update anyinclude statements in your NGINX configuration to be relativeto/workspace instead of/etc/nginx.

    • Some files such asgzip_params are not included. To referencethese files, include your own or copy fromGitHub. Files such asmime.types andfastcgi_params areavailable in/etc/nginx directory.

    • Some NGINX modules such asnginx-plus-module-ndk are not installed. Set the$docroot value or add the value manually in yourNGINX configuration file.

  • Optionally, you can specify a runtime version by:

    See theapp.yaml reference for more information.

Previous runtime versions

Warning: PHPversion 7.3 and earlier have reached end of support.App Engine blocks you from deploying your applications using runtimes that havereached end of support. We recommend that you migrate your app to use asupported versionof PHP or use acustom runtime.

To use PHPversion 7.3 and earlier, you must:

Support for other PHP runtimes

If you need to use a PHP version that isn'tsupported, you can create acustom runtime and select avalid base image with the PHP version you need.

For Google-supplied base images orDocker PHP base images,seeBuilding custom runtimes.

Customize NGINX

To define a custom configuration file, include thenginx-app.conf file in theroot directory of your project.

By default, the framework front controller uses theindex.php file. Youmight need to change this to something different for your project. For instance,the Symfony framework usesapp.php instead ofindex.php. You can change thefilename in theruntime_config section of yourapp.yaml file:

runtime:phpenv:flexruntime_config:operating_system:"ubuntu22"document_root:.front_controller_file:app.php

For version 7.3 and earlier, thenginx-app.conf configuration file is includedin the server section of the mainNGINX configuration file. For example, thedefault configurationphp-app.conf file, contains the following:

location / {# try to serve files directly, fallback to the front controllertry_files $uri /$front_controller_file$is_args$args;}

To define a custom configuration file, create thenginx-app.conf file in theroot directory of your project. The runtime overrides the default file with thefile you provide.

By default, the framework front controller uses theindex.php file. Youmight need to change this to something different for your project. For instance,the Symfony framework usesapp.php instead ofindex.php. You can change thefilename in theruntime_config section of yourapp.yaml file:

runtime:phpenv:flexruntime_config:document_root:.front_controller_file:app.php

OPcache

Enable OPcache in yourphp.ini file. Seethe officialdoc for how toconfigure OPcache.

To disable OPcache, create or edit the filephp.ini with the following line:

opcache.enable=0

Dependencies

The runtime looks for acomposer.json file in yourapplication's source directory and usescomposer to install anydependencies before starting your application. For more information on declaringand managing packages, seeUsing PHP Libraries.

Using PHP extensions

The following PHP extensions are pre-installed and enabled on the system:

Supported PHP versions

You can enable the following extensions using thephp.ini file:

v7.3 and earlier

The following PHP extensions are disabled by default.You can enable the following extensions in the using thephp.ini file:

To enable an extension, add aphp.ini file in the root of yourapplication with theextension directive:

; Enable the Redis extensionextension=redis.so; Enable the OpenTelemetry extension (must be in an opentelemetry section)[opentelemetry]extension=opentelemetry.so

Alternatively, you can also enable an extension by adding arequire to yourcomposer.json:

{"require":{"ext-redis":"*"}}

These packages allow the installation of most popular PHP extensions. If yourapplication requires additional operating-system level dependencies, you mustextend the PHP runtime or use acustom runtime to install theappropriate packages.

HTTPS and forwarding proxies

App Engine terminates the HTTPS connection at the load balancer and forwards therequest to your application. The NGINX server is configured to set the HTTPSenvironment variable ($_SERVER["HTTPS"]) toon when the request is made viaHTTPS.

Some applications also need to ascertain the user's IP address. This isavailable in the standardX-Forwarded-For header.

Disabled functions

The following functions are disabled with thedisable_functions directive inphp.ini:

  • exec
  • passthru
  • proc_open
  • proc_close
  • shell_exec
  • show_source
  • symlink
  • system

If you need any of the above functions, add aphp.ini file in the root ofyour application and change thedisable_functions directive. Alternatively,setwhitelist_functions in theruntime_config section inapp.yaml to acomma-delimited list of functions to allow.

For PHP version 7.3 and earlier, thesuhosin Security extension isinstalled and configured by default to run in simulation mode.Simulation mode logs the use of potentially dangerous functions, which will showin theCloud Logging UI. Turning the simulation mode offwill make your application exit when a potentially dangerous function is used.To enable this additional security feature, add aphp.ini in your project rootwith the following option:

; Prevent the use of potentially dangerous functions rather than logging themsuhosin.simulation = Off

Patched functions

The functionparse_str is patched and the second parameter ismandatory. If you callparse_str with only one parameter, it willthrow a warning and the function will not be called.

Available configurations

You can include the following configurations in theruntime_config section:

NameDescriptionDefault value
document_root SpecifiesDOCUMENT_ROOT for nginx and PHP. You must use a relative path from the project root directory.Required field
composer_flagsYou can override some of the composer flags with this key.--no-dev --prefer-dist
enable_stackdriver_integration Supported only forversion 7.3 and earlier. When set to true, the runtime will automatically enable Google Cloud Observability integration. This configuration requiresgoogle/cloud package v0.33 or higher.false
skip_lockdown_document_root Supported only forversion 7.3 and earlier. By default, the runtime will set a strict read-only permission on all the files and directories under thedocument_root directory. When set totrue, the runtime will skip changing the permission.false
whitelist_functions Supported only forversion 7.3 and earlier. A comma-separated list of function names to allowlist.An empty string
front_controller_fileDefault PHP file name for the directory access.index.php
nginx_conf_http_include Filename of a partial nginx config, which will be included in thehttp section in the main nginx config file.nginx-http.conf
nginx_conf_include Filename of a partial nginx config which will be included in theserver section in the main nginx config file.nginx-app.conf
nginx_conf_override Filename of a user supplied nginx configuration file, which will be used as the nginx main configuration file.nginx.conf
php_fpm_conf_override Filename of a user supplied php-fpm configuration file, which will be included at the bottom of the[app] section so that it will override the existing configurations.php-fpm.conf
php_ini_overrideFilename of a user supplied PHP configuration file.php.ini
supervisord_conf_addition Filename of a user supplied supervisord config file, which will be included in the main supervisord config file.additional-supervisord.conf
supervisord_conf_override Filename of a user supplied supervisord config file, which will override the main supervisord config file.supervisord.conf

You can control whether Nginx serves static files for matching URIs by setting theNGINX_SERVES_STATIC_FILES environment variable in thebuild_env_variables section of yourapp.yaml file:

runtime:phpenv:flexruntime_config:document_root:"web"operating_system:"ubuntu22"build_env_variables:NGINX_SERVES_STATIC_FILES:true

Configuring supervisord in the PHP runtime

The App Engine flexible environment usessupervisord to manage processes. By default,supervisord runsnginx andphp-fpm torun PHP web applications; however, some applications need to runexternal processes. Also such applications sometimes even do not neednginx norphp-fpm.

If you want to add a process managed bysupervisord, add a file namedadditional-supervisord.conf to the project root directory. Thefollowing is an example configuration file content for this case:

[program:quote-updater]command = php %(ENV_APP_DIR)s/worker.phpstdout_logfile = /dev/stdoutstdout_logfile_maxbytes=0stderr_logfile = /dev/stderrstderr_logfile_maxbytes=0user = www-dataautostart = trueautorestart = truepriority = 5stopwaitsecs = 20

If you want to replacenginx andphp-fpm with your process, add a filenamedsupervisord.conf to the project root directory. The followingis an example configuration file content for this case:

[supervisord]nodaemon = truelogfile = /dev/nulllogfile_maxbytes = 0pidfile = /var/run/supervisord.pid[program:react-server]command = php %(ENV_APP_DIR)s/index.phpstdout_logfile = /dev/stdoutstdout_logfile_maxbytes=0stderr_logfile = /dev/stderrstderr_logfile_maxbytes=0user = www-dataautostart = trueautorestart = truepriority = 5stopwaitsecs = 20

Extending the runtime

The App Engine flexible environment PHP runtime can be used to create a custom runtime.SeeCustomizing the PHP Runtime for moreinformation.

Environment variables

The following environment variables are set by the runtime environment:

Environment variableDescription
GAE_INSTANCEThe name of the current instance.
GAE_MEMORY_MBThe amount of memory available to the application process.
GAE_SERVICEThe service name specified in your application'sapp.yaml file, or if no service name is specified, it is set todefault.
GAE_VERSIONThe version label of the current application.
GOOGLE_CLOUD_PROJECTThe Project ID associated with your application, which is visible in the Google Cloud console
PORTThe port that will receive HTTP requests.

You can set additional environment variables withapp.yaml.

Metadata server

Each instance of your application can use theCompute Engine metadata server to query information about theinstance, including its host name, external IP address, instance ID, custommetadata, and service account information. App Engine doesn't allow you to setcustom metadata for each instance, but you can setproject-wide custom metadata and read it from your AppEngine and Compute Engine instances.

This example function uses the metadata server to get the external IP address ofan instance:

function get_external_ip_using_google_cloud(){    $metadata = new Google\Cloud\Core\Compute\Metadata();    $externalIp = $metadata->get(        'instance/network-interfaces/0/access-configs/0/external-ip');    return $externalIp;}function get_external_ip_using_curl(){    $url = 'http://metadata.google.internal/computeMetadata/v1/' .        'instance/network-interfaces/0/access-configs/0/external-ip';    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $url);    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Metadata-Flavor: Google'));    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    return curl_exec($ch);}

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 2025-12-15 UTC.