Last updated : Aug 26, 2019.
Overview
PHP is a server-side scripting language, and a powerful tool for making dynamic and interactive Web pages.
This lab shows how to deploy PHP application to Azure App service using Visual Studio Team Services.
Prerequisites for the lab
-
Microsoft Azure Account: You will need a valid and active Azure account for the Azure labs. If you do not have one, you can sign up for a free trial
-
If you are an active Visual Studio Subscriber, you are entitled for a $50-$150 credit per month. You can refer to this link to find out more information about this including how to activate and start using your monthly Azure credit.
-
If you are not a Visual Studio Subscriber, you can sign up for the FREE Visual Studio Dev Essentials program to create a Azure free account (includes 1 year of free services, $200 for 1st month).
-
-
You will need a Visual Studio Team Services Account. If you do not have one, you can sign up for free here
-
You will need a Personal Access Token to set up your project using the VSTS Demo Generator. Please see this article for instructions to create your token.
Note: You should treat Personal Access Tokens like passwords. It is recommended that you save them somewhere safe so that you can re-use them for future requests.
Setting Up the VSTS Project
-
Use the VSTS Demo Generator to provision the project on our VSTS account.
VSTS Demo Generator helps you create team projects on your VSTS account with sample content that include source code, work items,iterations, service endpoints, build and release definitions based on the template you choose during the configuration.
-
Provide a name for your project. Paste, the Octopus URL (VM’s DNS URL) that was created previously, API Key and click on Create Project.
-
Once the project is provisioned, click the URL to navigate to the project.
Note: This URL will automatically select Octopus template in the demo generator. If you want to try other projects, use this URL instead - https://vstsdemogenerator.azurewebsites.net/
Exercise 1: Endpoint Creation
Since the connections are not established during project provisioning, we will manually create the endpoints.
In VSTS, navigate to Services by clicking the gear icon , and click + New Service Endpoint. Select Azure Resource Manager. Specify connection name, select your subscription from the dropdown and click OK. We use this endpoint to connect VSTS with Azure.
You will be prompted to authorize this connection with Azure credentials.
Exercise 2: Configure Release Definition
We will use ARM template as Infrastructure as a Code in the release definition to provisions a Web App and a Web App Service Plan under the specified resource group.
-
Go to Releases under Build and Release tab, Select release definition PHP and click Edit
-
Go to Tasks and select Dev environment.
-
Under Azure Resource Group Deployment task, update Azure subscription and Location.
-
Under Azure App Service Deploy task, update Azure subscription and click Save.
Tasks Usage Azure Resource Group Deployment Uses the provided ARM template to create a resource group with App Service plan and App Service Azure App Service Deploy deploys a PHP application to the created App service
Exercise 3: Deploying the application
PHP is an interpreted language, so we don’t have to compile the code. Instead we will create an archive file which will be deployed to the Azure App Service.
Let’s make a code change to trigger a CI-CD pipeline to build and deploy the application.
-
Go to Code tab and navigate to the below path to edit the file.
php/config.php
-
Go to line number 11, modify PHP to DevOps for PHP using VSTS and commit the code.
-
Go to Builds tab under Build and Release tab to see the associated CI build in progress.
Let’s explore the build definition. The tasks used in the build definition are listed as shown.
Tasks Usage Archive files We will archive all the files in the folder to a zip file Copy Files Copy the ARM template and the Zip file to the artifact folder Publish Build Artifacts Publish the build artifacts so that it is available to the Release pipeline -
Once the build is complete, it triggers the CD pipeline. You can notice the linked release is in progress by navigating to Releases under Build and Release. The release will provision the Azure Web app and deploy the zip file generated by the associated build.
-
Alternatively, you can also login to the Azure Portal and navigate to the Resource Group that contains the Web App that was provisioned in the CD pipeline
-
Select the App Service and from the Overview tab, click Browse to see the application deployed.