title | layout | sidebar | permalink | folder |
---|---|---|---|---|
Deploy PHP application to Azure App Service using Azure Pipelines |
page |
vsts2 |
/labs/vstsextend/php/ |
/labs/vstsextend/php/ |
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.
In this lab, you will configure Azure Pipelines for a PHP app to deploy on to an Azure Web 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
- Refer Getting Started before you follow the lab exercises.
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{:target="_blank"} to provision project on your Azure DevOps Organization. This URL will automatically select the PHP template in the demo generator.
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.
php/config.php
-
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.
Let's explore the build definition. The tasks used in the build definition are listed below.
{% include note.html content= "We also have a YAML build pipeline if that's something you're interested in. To proceed through the YAML pipeline, choose PHP-YAML and click Edit to view the YAML pipeline. If you utilize the YAML pipeline, make sure to update the PHP release definition's artifact link." %}
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
Manage
link.- Click on the
+New Service Connection
button 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
Authorize
.
-
-
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.