Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Azure DevOps Services
Use Azure Pipelines continuous integration and continuous delivery (CI/CD) to build, deploy, and test your PHP projects.
Learn how to create a PHP pipeline, deploy a pipeline with a sample project to Azure App Service, and how to configure your environment.
To learn more about Azure App Service, see Create a PHP web app in Azure App Service.
Make sure you have the following items:
A GitHub account where you can create a repository. Create one for free.
An Azure DevOps organization. Create one for free. 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. To use Microsoft-hosted agents, your Azure DevOps organization must have access to Microsoft-hosted parallel jobs. You can either purchase a parallel job or you can request a free grant.
An Azure account. If you don't have one, you can create one for free.
Tip
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.
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:
https://github.com/Azure-Samples/basic-php-composer
Sign in to your Azure DevOps organization and go to your project.
Go to pipelines, and then select New pipeline.
Select your source location (GitHub, Azure Repos Git, Bitbucket Cloud, or other Git repositories).
Select the repository where your code is located.
Select PHP in the Configure tab.
Ensure the PHP version is 8.3.
Examine your new pipeline. When you're ready, select Save and run.
You're prompted to commit a new azure-pipelines.yml file to your repository. Select Save and run again.
If you want to watch your pipeline in action, select the build job.
You now have a working YAML pipeline (azure-pipelines.yml) in your repository that's ready for you to customize!
When you want to make changes to your pipeline, select your pipeline on the Pipelines page, and then Edit the azure-pipelines.yml file.
Read further to learn some of the more common ways to customize your pipeline.
Use a pipeline to build a PHP web app and deploy to Azure App Service. Azure App Service is an HTTP-based service for hosting web applications, REST APIs, and mobile back ends.
You can use tasks to archive your files, publish a build artifact, and then use the Azure Web App task to deploy to Azure App Service.
This pipeline has two stages: Build and Deploy. In the Build stage, PHP 8.3 is installed with composer. The app files are archived and uploaded into a package named drop
. During the Deploy phase, the drop
package gets deployed to Azure App Service as a web app.
trigger:
- main
variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: 'subscription-id'
# Web app name
webAppName: 'web-app-name'
# Agent VM image name
vmImageName: 'ubuntu-20.04'
# Environment name
environmentName: 'environment-name'
# Root folder under which your composer.json file is available.
rootFolder: $(System.DefaultWorkingDirectory)
stages:
- stage: Build
displayName: Build stage
variables:
phpVersion: '8.3'
jobs:
- job: BuildJob
pool:
vmImage: $(vmImageName)
steps:
- script: |
sudo update-alternatives --set php /usr/bin/php$(phpVersion)
sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)
sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)
sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)
sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
php -version
workingDirectory: $(rootFolder)
displayName: 'Use PHP version $(phpVersion)'
- script: composer install --no-interaction --prefer-dist
workingDirectory: $(rootFolder)
displayName: 'Composer install'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(rootFolder)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
displayName: 'Upload package'
artifact: drop
- stage: Deploy
displayName: 'Deploy Web App'
dependsOn: Build
condition: succeeded()
jobs:
- deployment: DeploymentJob
pool:
vmImage: $(vmImageName)
environment: $(environmentName)
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp@1
displayName: 'Deploy Azure Web App'
inputs:
azureSubscription: $(azureSubscription)
appName: $(webAppName)
package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip
Use Azure Pipelines to build your PHP projects without setting up infrastructure.
PHP is preinstalled on Microsoft-hosted agents, along with many common libraries per PHP version. You can use Linux, macOS, or Windows agents to run your builds. For more information and the exact versions of PHP that get preinstalled, see Microsoft-hosted agents.
On the Microsoft-hosted Ubuntu agent, multiple versions of PHP are installed. A symlink at /usr/bin/php
points to the currently set PHP version, so that when you run php
, the set version executes.
To use a PHP version other than the default, the symlink can be pointed to that version using the update-alternatives
tool. Set the PHP version that you want by adding the following snippet to your azure-pipelines.yml
file and change the value of the phpVersion variable.
pool:
vmImage: 'ubuntu-20.04'
variables:
phpVersion: 8.2
steps:
- script: |
sudo update-alternatives --set php /usr/bin/php$(phpVersion)
sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)
sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)
sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)
sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
php -version
displayName: 'Use PHP version $(phpVersion)'
To use Composer to install dependencies, add the following snippet to your azure-pipelines.yml
file.
- script: composer install --no-interaction --prefer-dist
displayName: 'composer install'
To run tests with phpunit, add the following snippet to your azure-pipelines.yml
file.
- script: ./phpunit
displayName: 'Run tests with phpunit'
To save the artifacts of this build with the build record, add the following snippet to your azure-pipelines.yml
file.
Optionally, customize the value of rootFolderOrFile to alter what is included in the archive.
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(system.defaultWorkingDirectory)'
includeRootFolder: false
- task: PublishBuildArtifacts@1
If your composer.json is in a subfolder instead of the root directory, you can use the --working-dir
argument to tell composer what directory to use. For example, if your composer.json is inside the subfolder pkgs
composer install --no-interaction --working-dir=pkgs
You can also specify the absolute path, using the built-in system variables:
composer install --no-interaction --working-dir='$(system.defaultWorkingDirectory)/pkgs'
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Learning path
Build applications with Azure DevOps learning path - Training
In this learning path, find out how to collaborate with others to continuously build, test, and verify your applications using Azure Pipelines and GitHub.
Certification
Microsoft Certified: Azure Developer Associate - Certifications
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.
Documentation
Create your first pipeline - Azure Pipelines
Create your first pipeline in Azure Pipelines, Azure DevOps, & Team Foundation Server
Deploy to Azure services - Azure Pipelines
See articles that describe how different Azure services support continuous integration (CI) and continuous delivery (CD) with Azure Pipelines.
Azure Pipelines documentation - Azure DevOps
Configure and manage continuous integration and continuous delivery (CI/CD) for the app and platform of your choice.