PHP 5 已終止支援,並將於 2026 年 1 月 31 日
淘汰。淘汰後,您將無法部署 PHP 5 應用程式,即使貴機構先前曾使用機構政策重新啟用舊版執行階段的部署作業,也無法部署。現有的 PHP 5 應用程式在
淘汰日期後仍會繼續執行並接收流量。建議您
改用系統支援的最新 PHP 版本。
php.ini 檔案
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
您的 App Engine 應用程式可包含 php.ini 檔案,可讓您用來自訂 PHP 解譯器指令的行為。
關於 php.ini
php.ini
檔案應放在應用程式的基礎目錄中 (與 app.yaml
檔案相同的目錄)。系統會在 PHP 解譯器初始化時載入這個檔案,並且之後才會執行應用程式的程式碼。
此檔案所遵循的語法與其他 .ini 檔案的語法相同。簡單的範例如下:
; This is a simple php.ini file on App Engine
;
; This is a directive set to "On"
widget_compression = "On"
核心指令清單及其可變更模式值已發布在 php.net 上。擴充功能處理的 php.ini
指令已在擴充功能的各自頁面中記錄。
您可覆寫具備下列其中一個可變更模式值的任何 PHP 指令:
PHP_INI_SYSTEM
PHP_INI_ALL
PHP_INI_PERDIR
請注意,某些功能已在 PHP 的 App Engine 實作中停用。以這些功能為目標的指令不會產生任何作用。
extension
指令可用來啟用一組
可動態載入的擴充功能。
App Engine 的 PHP 指令
下列指令專屬於 App Engine 環境,並且可包含在 php.ini 檔案中。
google_app_engine.enable_curl_lite
:設為「1」時即會啟用「cURL 精簡版」,這是 App Engine 專屬的內建 cURL 版本。「cURL 精簡版」的使用方式與標準版 cURL 函式完全相同,但精簡版不會呼叫通訊端,而是在背景中呼叫網址擷取。因此,沒有網址擷取對等項目的函式會傳回 CurlLiteMethodNotSupportedException
。注意事項:應用程式無法同時啟用「curl.so」擴充功能和「cURL 精簡版」,因為後者會導致 cURL 函式超載。
google_app_engine.enable_functions
- 在 App Engine 中軟性停用的函式,但可使用此指令重新啟用。以逗號分隔字串的形式列出函式名稱:google_app_engine.enable_functions = "phpversion, phpinfo"
google_app_engine.allow_include_gs_buckets
- 允許應用程式使用 include
或 require
陳述式,搭配儲存在 Google Cloud Storage 中的檔案。
注意:您可以為預設值區使用 #default#
,這個資料值會在執行階段中自動替換為目前的預設值區名稱。
例如,您可以使用逗號分隔的字串,列出預設值區,以及包含檔案的 bucket_1
和 bucket_2
值區:
google_app_engine.allow_include_gs_buckets = "#default#, bucket_1, bucket_2"
您也可以指定要納入的值區和檔案路徑,例如:
google_app_engine.allow_include_gs_buckets = "bucket_1/path_x"
系統在檢查會從 Google Cloud Storage 納入哪些檔案時,會將提供的路徑視為前置字串;此前置字串必須符合檔案名稱的開頭,才能納入或要求該檔案。舉例來說,以上述路徑範例為例,提供的路徑可讓使用者納入來自 gs://bucket_1/path_x/...
的檔案,因為前置字串相符,但無法納入來自 gs://bucket_1 or gs://bucket_1/path_y/
的檔案,因為前置字串不相符。
如果上傳的檔案已移至允許的包含資料夾,系統會產生警告,提醒使用者可能遭到 LFI 攻擊。發生這種情況時,您應考慮使用限制更嚴格的路徑。
注意:路徑視同檔案的前置字串,因此也能包含特定檔案,例如 google_app_engine.allow_include_gs_buckets = "bucket_1/path_x.ext", "bucket_2/path_z/some_file.ext
。
google_app_engine.disable_readonly_filesystem
:根據預設,PHP 應用程式無法寫入檔案系統。將此指令設為「1」會解除本機開發環境的限制。
不過,這項設定不會套用至在實際工作環境中運作的應用程式,因為這類應用程式均須符合沙箱限制。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-04 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eThe \u003ccode\u003ephp.ini\u003c/code\u003e file, placed in the base directory of an App Engine application, allows customization of PHP interpreter directives before application code execution.\u003c/p\u003e\n"],["\u003cp\u003eYou can override PHP directives with changeable mode values such as \u003ccode\u003ePHP_INI_SYSTEM\u003c/code\u003e, \u003ccode\u003ePHP_INI_ALL\u003c/code\u003e, and \u003ccode\u003ePHP_INI_PERDIR\u003c/code\u003e, excluding those targeting disabled functions.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine provides specific directives within \u003ccode\u003ephp.ini\u003c/code\u003e, including \u003ccode\u003egoogle_app_engine.enable_curl_lite\u003c/code\u003e to use "cURL lite," and \u003ccode\u003egoogle_app_engine.enable_functions\u003c/code\u003e to re-enable certain soft-disabled functions.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egoogle_app_engine.allow_include_gs_buckets\u003c/code\u003e directive permits the use of \u003ccode\u003einclude\u003c/code\u003e or \u003ccode\u003erequire\u003c/code\u003e statements with files stored in specified Google Cloud Storage buckets, with path prefix matching.\u003c/p\u003e\n"],["\u003cp\u003eIn local development, \u003ccode\u003egoogle_app_engine.disable_readonly_filesystem\u003c/code\u003e can be set to "1" to allow filesystem writing, but this is not applicable in production due to sandbox restrictions.\u003c/p\u003e\n"]]],[],null,["You can include a php.ini file with your App Engine application. This file\nlets you customize the behavior of the PHP interpreter directives.\n\nAbout php.ini\n\nThe `php.ini` file should be\nplaced in the base directory of an application (the same directory as the\n`app.yaml` file). It is loaded when the PHP interpreter is\ninitialized, and before your application code is run.\n\nThe file follows the same syntax as\n[other .ini files](https://en.wikipedia.org/wiki/INI_file). A simple\nexample might look like: \n\n```php\n; This is a simple php.ini file on App Engine\n;\n; This is a directive set to \"On\"\nwidget_compression = \"On\"\n```\n\nA list of the core directives, along with their changeable mode values,\n[is published on php.net](http://www.php.net/manual/en/ini.list.php).\nThe `php.ini` directives handled by extensions are documented on the\nrespective pages of the extensions themselves.\n\nYou may override any PHP directive that has one of the following changeable mode values:\n\n- `PHP_INI_SYSTEM`\n- `PHP_INI_ALL`\n- `PHP_INI_PERDIR`\n\nNote that some functions\n[have been\ndisabled in the App Engine implementation of PHP](/appengine/docs/legacy/standard/php/runtime#disabled_functions). Directives that target\nthese functions will have no effect.\n\nA set of [dynamically loadable extensions](/appengine/docs/legacy/standard/php/runtime#dynamically_loadable_extensions) can be enabled using the\n`extension` directive.\n\nPHP Directives for App Engine\n\nThe following directives are specific to the App Engine environment. They can\nbe included in the php.ini file.\n\n- **`google_app_engine.enable_curl_lite`** - Enables \"cURL lite\", a built-in, App Engine-specific version of cURL, when set to \"1\". \"cURL lite\" can be used exactly as you would use the standard [cURL functions](http://php.net/manual/en/ref.curl.php), but it calls [URL Fetch](/appengine/docs/legacy/standard/php/issue-requests) under the hood rather than sockets, thus functions with no URL Fetch equivalent, throw a `CurlLiteMethodNotSupportedException`.\n\n Note: An app can't enable the \"curl.so\" extension and \"cURL lite\" at the same time,\n as the latter overloads the cURL functions.\n- **`google_app_engine.enable_functions`** - Functions that have been [soft\n disabled](/appengine/docs/legacy/standard/php/runtime#functions_that_can_be_manually_enabled) in App Engine, but can be re-enabled using this directive. List the function names in a comma delimited string: \n\n ```\n google_app_engine.enable_functions = \"phpversion, phpinfo\"\n ```\n- **`google_app_engine.allow_include_gs_buckets`** - Allows your application to use the [`include`](http://php.net/manual/en/function.include.php) or [`require`](http://us1.php.net/manual/en/function.require.php) statements with files stored in [Google Cloud\n Storage](/appengine/docs/legacy/standard/php/googlestorage).\n\n \u003cbr /\u003e\n\n Note: You can use `#default#` for the default bucket; this value\n will be automatically replaced at runtime with your current default bucket name.\n\n For example, list the default bucket, along with buckets `bucket_1` and `bucket_2`\n containing the files in a comma delimited string: \n\n ```\n google_app_engine.allow_include_gs_buckets = \"#default#, bucket_1, bucket_2\"\n ```\n\n You can also specify a bucket and path to files that can be included, for example: \n\n ```\n google_app_engine.allow_include_gs_buckets = \"bucket_1/path_x\"\n ```\n\n When the check is performed for which files may be included from Google Cloud Storage, the\n supplied path is treated as a prefix that must match the start of the file name in order for it\n to be included or required. For example using the path example above, the supplied\n path would allow users to include files from `gs://bucket_1/path_x/...`\n because the prefix matches but not from `gs://bucket_1 or gs://bucket_1/path_y/` because\n the prefix doesn't match.\n\n If an uploaded file is moved to an allowed include bucket, a warning\n is generated to alert the user to a potential\n [LFI](https://en.wikipedia.org/wiki/File_inclusion_vulnerability)\n attack. If this happens, you should consider using a more\n restrictive path.\n\n **Note:** the path is treated as a file\n prefix; so it could include a specific file\n as well, for example, `google_app_engine.allow_include_gs_buckets = \"bucket_1/path_x.ext\", \"bucket_2/path_z/some_file.ext`.\n- **`google_app_engine.disable_readonly_filesystem`** - By default PHP applications are not allowed to write to the filesystem. Setting this directive to \"1\" will lift the restriction for the local development environment. However, the setting does not apply to applications running in production, which are always subjected to the [sandbox restrictions](/appengine/docs/legacy/standard/php/runtime#the_sandbox)."]]