You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ARM模板创建PHP运行时Azure App Service遇默认.NET问题咨询

解决ARM模板部署PHP App Service却默认使用.NET环境的问题

我仔细看了你提供的ARM模板,问题大概率出在运行时环境的配置细节或者对应的App Service Plan的操作系统类型上。你已经指定了phpVersion,但可能因为以下核心原因导致默认启用了.NET环境:

1. 区分Windows和Linux App Service Plan的配置差异

App Service的运行时配置逻辑会随着Plan的操作系统不同而变化,这是最容易踩坑的点:

  • 如果你的App Service Plan是Windows类型:
    Windows环境下虽然支持phpVersion属性,但默认会保留.NET的基础配置,你需要显式禁用.NET运行时,才能强制切换到PHP环境。
  • 如果你的App Service Plan是Linux类型:
    Linux环境不识别phpVersion这个属性,必须改用linuxFxVersion来指定PHP运行时,格式为PHP|<版本号>。

2. 修改后的模板示例

Windows Plan 适配版本

在siteConfig中新增netFrameworkVersion并设置为vNone,彻底禁用.NET默认配置:

{
  "apiVersion": "2018-11-01",
  "name": "[concat(parameters('webSiteName'),copyIndex(1))]",
  "type": "Microsoft.Web/sites",
  "location": "[resourceGroup().location]",
  "copy": {
    "name": "webloop",
    "count": 2
  },
  "identity": {
    "type": "SystemAssigned"
  },
  "dependsOn": [
    "[concat(variables('targetResourceId'),copyIndex(1))]",
    "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
  ],
  "tags": {
    "project": "zdemo"
  },
  "properties": {
    "name": "[concat(parameters('webSiteName'),copyIndex(1))]",
    "serverFarmId": "[concat(variables('targetResourceId'),copyIndex(1))]",
    "siteConfig": {
      "phpVersion": "7.3",
      "netFrameworkVersion": "vNone", // 新增:强制禁用.NET运行时
      "use32BitWorkerProcess": false,
      "connectionStrings": [
        {
          "name": "connstr",
          "connectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2015-05-01-preview').key1,';EndpointSuffix=core.windows.net')]",
          "type": "Custom"
        }
      ]
    }
  }
}

Linux Plan 适配版本

替换phpVersion为linuxFxVersion,符合Linux环境的运行时配置规范:

{
  "apiVersion": "2018-11-01",
  "name": "[concat(parameters('webSiteName'),copyIndex(1))]",
  "type": "Microsoft.Web/sites",
  "location": "[resourceGroup().location]",
  "copy": {
    "name": "webloop",
    "count": 2
  },
  "identity": {
    "type": "SystemAssigned"
  },
  "dependsOn": [
    "[concat(variables('targetResourceId'),copyIndex(1))]",
    "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
  ],
  "tags": {
    "project": "zdemo"
  },
  "properties": {
    "name": "[concat(parameters('webSiteName'),copyIndex(1))]",
    "serverFarmId": "[concat(variables('targetResourceId'),copyIndex(1))]",
    "siteConfig": {
      "linuxFxVersion": "PHP|7.3", // 替换phpVersion为Linux专属配置项
      "use32BitWorkerProcess": false,
      "connectionStrings": [
        {
          "name": "connstr",
          "connectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2015-05-01-preview').key1,';EndpointSuffix=core.windows.net')]",
          "type": "Custom"
        }
      ]
    }
  }
}

额外验证步骤

  • 确认你的App Service Plan的kind属性:Linux计划需设置为linux,Windows计划则为app(默认值);
  • 部署完成后,可在Azure门户的App Service -> 配置 -> 常规设置中,直接查看运行时堆栈是否已切换为PHP。

内容的提问来源于stack exchange,提问作者Ziad H Hassan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:44:27