Azure Pipelines helps you set up a highly customizable continuous integration (CI) and continuous delivery (CD) pipeline to target app services, virtual machines, or containers in Azure whether you are developing a .NET, Java, Node, PHP, or a Python app.
Upon completion of this lab, you will be able to:
- Set up a PHP Azure DevOps Project with Azure DevOps Demo Generator
- Set up an Azure CI Pipeline
- Set up an Azure Web App within the Release pipeline and deploy the PHP Application to the Azure Web App
Before you begin
- Refer Getting Started before you follow the lab exercises.
Exercise 1: Create a PHP application project using the Azure DevOps Demo Generator
In this practice lab, you are going to work on a PHP project. The purpose is to create a system for the developer to understand the list of tasks that are triggered once the code is pushed to a shared repository.
While the code is a simple PHP application, you will use Azure Command Line Interface(CLI) to provision the infrastructure to deploy the build artifacts.
- Use the Azure DevOps Demo Generator to provision project on your Azure DevOps Organization. This URL will automatically select the PHP template in the demo generator.
Exercise 2: Commit code changes which triggers a CI build
The Azure DevOps Demo Generator creates a Git repository with code in your Azure DevOps Organization. You are going to update the code and commit changes.
Navigate to Repos tab in the Azure DevOps portal and navigate to the below path to edit the file.
Scroll down to line number 11, select Edit , modify PHP to DevOps for PHP using Azure DevOps and choose Commit to save the changes to the code.
Go to Builds tab under Pipelines. You should now see a build is in progress. The changes you just made are automatically built which will be deployed via the Release pipeline. Click the ellipsis to View build results.
Examine the Build Definition
Let’s explore the build definition. The tasks used in the build definition are listed below.
|Archive files||Since PHP is an interpreted language, there is no need to compile the code. Instead, the code is archived into a Zip file.|
|Publish Build Artifacts||Publish the build artifacts so that it is available to the Release pipeline|
Exercise 3: Configure the Release Definition
Once the build is complete, let us configure the CD pipeline. You will notice a release definition by navigating to Releases under the Pipelines section. The release will provision an Azure Web app using the Azure CLI and deploy the zip file to the Web App generated by the associated build.
Under the Releases under Pipelines tab, select release definition PHP and click on Edit.
Go to Tasks and select Dev environment.
Select the Azure CLI task, choose the Azure subscription. There are 2 ways of choosing the Azure subscription.
If your subscription is not listed or if you want to use an existing service principal, click the
- Click on the
+New Service Connectionbutton and select the Azure Resource Manager option. Provide Connection name, select the Azure Subscription from the list and then click on the Ok button. The Azure credentials will be required to authorize the connection.
- Click on the
If the subscription is already listed, select the Azure subscription from the list and click
Azure CLI is used in the inline script to create the following in Azure -
- Resource Group
- App Service Plan
- App Service
The variables are defined in the Variables section.
Select the Azure App Service Deploy task and pick Azure subscription from the dropdown list, then click on Save.
Tasks Usage Azure CLI Executes the inline batch scripts to provision a Web App within a resource group Azure App Service Deploy Deploys the PHP code to the provisioned App service
Queue the saved release definition to deploy the latest build artifacts to the Azure Web App.
Once the release succeeds, navigate to the created Web App to view the PHP application.
In this lab, you have learnt how to deploy a PHP application on Azure Web App with Azure Pipelines.