The PHP runtime Stay organized with collections Save and categorize content based on your preferences.
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:
Install
gcloud CLIversion420.0.0 or later. You can update yourCLI tooling by running thegcloud components updatecommand. To view your installed version, you can run thegcloud versioncommand.Include the
runtime_configandoperating_systemsettings in yourapp.yamlfileto specify an operating system.Declare the document root for your application in the
app.yamlfile: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_rootsetting.The source code is located in the
/workspacedirectory instead of the root directory (/). If you override any configuration,theNGINXorsupervisorprocesses reference your configuration file in this directory. Toupdate corresponding references, you must:Update any
includestatements in your NGINX configuration to be relativeto/workspaceinstead of/etc/nginx.Some files such as
gzip_paramsare not included. To referencethese files, include your own or copy fromGitHub. Files such asmime.typesandfastcgi_paramsareavailable in/etc/nginxdirectory.Some NGINX modules such as
nginx-plus-module-ndkare not installed. Set the$docrootvalue or add the value manually in yourNGINXconfiguration file.
Optionally, you can specify a runtime version by:
Including the
runtime_versionsetting in yourapp.yaml. By default, the latest PHP version is used iftheruntime_versionsetting is not specified.To specify PHP 8.4 on Ubuntu 22:
runtime:phpenv:flexruntime_config:operating_system:"ubuntu22"runtime_version:"8.4"document_root:.To specify the latest supported PHP version on Ubuntu 22:
runtime:phpenv:flexruntime_config:operating_system:"ubuntu22"document_root:.
Including a PHP version in the
composer.jsonfile.{"require":{"php":"8.4.*"}}When you specify a PHP version using MAJOR, MINOR, and PATCH,replace PATCHwith
*. Use the formatMAJOR.MINOR.*.The PHP runtime is regularly updatedto the latest release version and only supports one release version at atime, so specifying a release version can cause an error.
See the
app.yamlreference 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:
Declare the document root for your application. You can do this in your
app.yamlfile:runtime:phpenv:flexapi_version:1runtime_config:document_root:.Although you can specify the project root (
.) directory as thedocument root, we recommend that you use a subdirectory for thedocument_rootsetting.Specify a PHP version in the
composer.jsonfile to preventyour application from automatically upgrading when a new version ofPHP becomes available.{"require":{"php":"7.3.*"}}When you specify a PHP version using MAJOR, MINOR, and PATCH,replace PATCHwith `*`. Use the format
MAJOR.MINOR.*.The PHP runtime is regularly updatedto the latest release version and only supports one release version at atime, so specifying a release version can cause an error.
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.phpFor 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.phpOPcache
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=0Dependencies
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
- BCMath
- Bzip2
- Calendar
- ctype
- cURL
- DBA
- DOM
- Enchant
- EXIF
- Fileinfo
- Filter
- FTP
- GD
- Gettext
- GMP
- iconv
- Intl
- LDAP
- libxml
- mbstring
- MySQLi
- MySQLND
- OpenSSL
- pcntl
- PDO
- PDO_MYSQL
- PDO_PGSQL
- PDO_SQLITE
- PGSQL
- Phar
- POSIX
- Session
- Shmop
- SimpleXML
- SOAP
- Sockets
- SQLite3
- Tidy
- Tokenizer
- XML
- XMLReader
- XMLWriter
- XSL
- zend_test
- Zip (Ubuntu 22 only)
- Zlib
You can enable the following extensions using thephp.ini file:
- gRPC
- ImageMagick
- Mailparse
- Memcached
- mongodb
- OpenCensus
- OpenTelemetry (PHP version 8.1 and later)
- OPcache
- protobuf
- Redis
v7.3 and earlier
- APCu
- Bzip2
- cURL
- FPM
- GMP
- mbstring
- mcrypt
- libsodium
- Memcached
- MySQL (PDO) (uses mysqlnd)
- MySQLi (uses mysqlnd)
- OPcache
- OpenSSL
- pcntl
- PostgreSQL
- PostgreSQL (PDO)
- Readline
- recode
- sem
- Sockets
- Zip
- Zlib
The following PHP extensions are disabled by default.You can enable the following extensions in the using thephp.ini file:
- amqp
- APM (7.0+)
- BCMath
- Bitset
- Calendar
- Cassandra
- couchbase (7.0+)
- ds (7.0+)
- eio
- ev
- event
- Exif
- FTP
- GD (with PNG, JPEG and FreeType support)
- gettext
- gRPC
- hprose
- igbinary
- intl
- ImageMagick
- jsond
- krb5
- lua (7.0+)
- LZF
- memprof
- mongodb
- MySQL (5.6)
- oauth
- OpenCensus
- PCNTL
- Phalcon (5.6, 7.0)
- pq
- protobuf
- rdkafka
- Redis
- SeasLog
- Shmop
- SOAP
- SQLite3
- SQLite (PDO)
- stomp
- swoole
- sync
- tcpwrap
- timezonedb
- v8js (7.0+)
- vips (7.0+)
- XMLRPC
- XSL
- yaconf (7.0+)
- yaf
- yaml
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.soAlternatively, 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:
execpassthruproc_openproc_closeshell_execshow_sourcesymlinksystem
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 = OffPatched 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:
| Name | Description | Default value |
|---|---|---|
document_root | SpecifiesDOCUMENT_ROOT for nginx and PHP. You must use a relative path from the project root directory. | Required field |
composer_flags | You 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_file | Default 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_override | Filename 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:trueConfiguring 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 = 20If 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 = 20Extending 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 variable | Description |
|---|---|
GAE_INSTANCE | The name of the current instance. |
GAE_MEMORY_MB | The amount of memory available to the application process. |
GAE_SERVICE | The service name specified in your application'sapp.yaml file, or if no service name is specified, it is set todefault. |
GAE_VERSION | The version label of the current application. |
GOOGLE_CLOUD_PROJECT | The Project ID associated with your application, which is visible in the Google Cloud console |
PORT | The 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.