Build & deploy to PHP web app

Azure Pipelines

A web app is a lightweight way to host a web application. In this step-by-step guide, learn how to create a pipeline that continuously builds and deploys your PHP app. Your team can then automatically build each commit at GitHub and deploy the change to an Azure App Service.


Make sure you have the following items:

  • A GitHub account where you can create a repository. If you don't have one, you can create one for free.

  • An Azure DevOps organization. If you don't have one, you can create one for free. (An Azure DevOps organization is different from your GitHub organization. You can give your DevOps organization and your GitHub organization the same name if you want alignment between them.)

    If your team already has one, then make sure you're an administrator of the Azure DevOps project that you want to use.

  • An ability to run pipelines on Microsoft-hosted agents. You can either purchase a parallel job or you can request a free tier. To request a free tier, follow the instructions in this article. Please note that it may take us 2-3 business days to grant the free tier.

  • An Azure account. If you don't have one, you can create one for free.


    If you're new at this, the easiest way to get started is to use the same email address as the owner of both the Azure Pipelines organization and the Azure subscription.

Get the code

If you already have an app at GitHub that you want to deploy, you can create a pipeline for that code. But, if you're a new user, you might get a better start by using our sample code. In that case, fork the following repo at GitHub:

Create an Azure App Service

Sign in to the Azure Portal, and then select the Cloud Shell button in the upper-right corner.

Create an Azure App Service on Linux.

# Create a resource group
az group create --location westus --name myapp-rg

# Create an app service plan of type Linux
az appservice plan create -g myapp-rg -n myapp-service-plan --is-linux

# Create an App Service from the plan with PHP as the runtime
az webapp create -g myapp-rg -p myapp-service-plan -n my-app-name --runtime "PHP|7.0"

Create the service connection

  1. From your project dashboard, select Project settings. If you don't have a project, create a project now.

  2. On the settings page, select Pipelines > Service connections, select New service connection, and then select Azure Resource Manager.

  3. Select Service principal (automatic) and Next.

  4. The Add an Azure Resource Manager service connection dialog box appears.

    • Scope Select Subscription.
    • Subscription Select your Azure portal subscription.
    • Resource Group Select the resource group you created earlier.
    • Service connection name Type a name and then copy and paste it into a text file so you can use it later.
    • Select Grant access permission to all pipelines.

    New service connection dialog box


If you need to create a connection to an Azure subscription that's owned by someone else, see Create an Azure Resource Manager service connection with an existing service principal.

Create the pipeline

  1. Sign in to your Azure DevOps organization and go to your project.

  2. Go to Pipelines, and then select New pipeline.

  3. Do the steps of the wizard by first selecting GitHub as the location of your source code.

  4. You might be redirected to GitHub to sign in. If so, enter your GitHub credentials.

  5. When you see the list of repositories, select your repository.

  6. You might be redirected to GitHub to install the Azure Pipelines app. If so, select Approve & install.

  1. When you see the Configure tab, select PHP. Your new pipeline appears.

  2. Check out your pipeline, and then select Save and run to see the pipeline in action.

  3. Select Save and run, after which you're prompted for a commit message because the azure-pipelines.yml file gets added to your repository. After editing the message, select Save and run again.

We automatically created this pipeline because your code appeared to be a good match for the PHP Azure Pipelines template.

Edit the pipeline

After the pipeline has run, select the vertical ellipses in the upper-right corner of the window and then select Edit pipeline.

Set some variables for your deployment

# at the top of your YAML file 
# set some variables that you'll need when you deploy
  # the name of the service connection that you created above
  serviceConnectionToAzure: name-of-your-service-connection
  # the name of your web app here is the same one you used above
  # when you created the web app using the Azure CLI
  appName: my-app-name
  # the name of your functionApp is what you provided as
  # stagingDirectory in pom.xml
  functionAppName: 'javafunctions'
# ...

Deploy to your app service

# add these as the last steps (below all the other `task` items under `steps`)
# to deploy to your app service
- task: ArchiveFiles@1
  displayName: Archive files
    rootFolder: $(System.DefaultWorkingDirectory)
    includeRootFolder: false
    archiveType: zip

- task: PublishBuildArtifacts@1
  displayName: Publish Artifact
    PathtoPublish: $(build.artifactstagingdirectory)

- task: AzureWebApp@1
  displayName: Azure Web App Deploy
    azureSubscription: $(serviceConnectionToAzure)
    appType: webAppLinux
    appName: $(appName)
    package: $(build.artifactstagingdirectory)/**/*.zip

Run the pipeline and check out your site

You're now ready to save your changes and try it out!

  1. Select Save in the upper-right corner of the editor.

  2. In the dialog box that appears, add a Commit message such as add deployment to our pipeline, and then select Save.

  3. In the pipeline editor, select Run.

  4. When you see the Build #nnnnnnnn.n has been queued message, select the number link to see your pipeline in action.

After the pipeline has run, check out your site!

Clean up resources

Whenever you're done with the resources you created, you can use the following command to delete them:

az group delete --name myapp-rg

Enter y when you're prompted.