创建一个Arm模板以在azure应用程序服务上托管php应用程序

时间:2019-09-09 08:12:46

标签: json azure azure-web-sites arm-template azure-template

我正在尝试使用ARM模板在运行时创建一个使用PHP的应用程序服务,但是默认配置始终导致创建.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",
          "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"
            }
          ]
        }
      }
    }

在这里我选择了php版本,但是在部署模板时,我看到默认值为.Net

1 个答案:

答案 0 :(得分:1)

根据我的测试,您可以使用以下模板在Azure上创建一个PHP Web应用。

template.json

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "subscriptionId": {
            "type": "string"
        },
        "name": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "hostingEnvironment": {
            "type": "string"
        },
        "hostingPlanName": {
            "type": "string"
        },
        "serverFarmResourceGroup": {
            "type": "string"
        },
        "alwaysOn": {
            "type": "bool"
        },
        "currentStack": {
            "type": "string"
        },
        "phpVersion": {
            "type": "string"
        }
    },
    "resources": [
        {
            "apiVersion": "2018-02-01",
            "name": "[parameters('name')]",
            "type": "Microsoft.Web/sites",
            "location": "[parameters('location')]",
            "tags": {},
            "dependsOn": [],
            "properties": {
                "name": "[parameters('name')]",
                "siteConfig": {
                    "appSettings": [],
                    "metadata": [
                        {
                            "name": "CURRENT_STACK",
                            "value": "[parameters('currentStack')]"
                        }
                    ],
                    "phpVersion": "[parameters('phpVersion')]",
                    "alwaysOn": "[parameters('alwaysOn')]"
                },
                "serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
                "hostingEnvironment": "[parameters('hostingEnvironment')]",
                "clientAffinityEnabled": true
            }
        }
    ]
}

parameters.json

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "subscriptionId": {
            "value": " "
        },
        "name": {
            "value": " "
        },
        "location": {
            "value": "Southeast Asia"
        },
        "hostingEnvironment": {
            "value": ""
        },
        "hostingPlanName": {
            "value": " "
        },
        "serverFarmResourceGroup": {
            "value": " "
        },
        "alwaysOn": {
            "value": true
        },
        "currentStack": {
            "value": "php"
        },
        "phpVersion": {
            "value": "7.3"
        }
    }
}

enter image description here

enter image description here

有关更多详细信息,请参阅document