Deploying PHP Applications to Azure App Service with Azure DevOps

This post is about deploying PHP applications to Azure App Service with Azure DevOps. Recently I had to deploy PHP application to Azure App Service. You can deploy it to Azure App Service using FTP, since there is no compilation steps required. If you’re using Composer – Dependency Manager for PHP, you need to run the composer install before deploying the files to app service via FTP. Instead of using deploying FTP deploy the app, I choose to implement a deployment pipeline, so that I don’t want to share the FTP credentials to the developer. And if I enable continuous integration – when ever developer commit some changes, can be deployed automatically to the app service.

In the Azure DevOps I used a classic editor option to create the pipeline. Firstly I created a pipeline with empty job since there is no predefined task available for PHP deployment. In the tasks I added first Bash script task – for running the command – composer install –no-interaction –prefer-dist. Next I added Archive files task. In this task make sure, un select the Prepend root folder name to archive paths option.

Next I am adding Publish Artifact task, so that I can publish the Zip file from the directory to the artifacts location. And finally I am adding Azure App Service deployment task. In the task you need to select the Package or folder as the $(Build.ArtifactStagingDirectory)/**/*.zip file – which the output of the Publish Artifact Task.

And you need to choose the Runtime Stack – 7.4 – the PHP runtime you would like to use. And here is the complete build pipeline.

And here is the YAML – Exported from Azure DevOps.

repository: self
type: git
ref: main
job: Job_1
displayName: Agent job 1
vmImage: ubuntu-20.04
checkout: self
clean: true
task: [email protected]
displayName: Composer Install
targetType: inline
script: composer install –no-interaction –prefer-dist
task: [email protected]
displayName: Archive $(System.DefaultWorkingDirectory)
rootFolderOrFile: $(System.DefaultWorkingDirectory)
includeRootFolder: false
task: [email protected]
displayName: Publish Artifact: drop’
task: [email protected]
displayName: Azure App Service Deploy: Php Web App’
ConnectedServiceName: 643990e2-059d-4e5a-87e0-e9484682897e
WebAppKind: webAppLinux
WebAppName: azure-php-web-app
Package: $(Build.ArtifactStagingDirectory)/**/*.zip
RuntimeStack: PHP|7.4

Here few helpful links which talks about deploying PHP apps to Azure App Service.

Build and test PHP apps
Build and deploy to a PHP web app

Happy Programming 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *