Last updated : Feb 14, 2018.

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

  1. 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).

  2. You will need a Visual Studio Team Services Account. If you do not have one, you can sign up for free here

  3. 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.

Setting Up the VSTS Project

  1. 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.

    VSTS Demo Generator

  2. 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.

  3. Once the project is provisioned, click the URL to navigate to the project.

    VSTS Demo Generator

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 gear , 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.

services_endpoint

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.

  1. Go to Releases under Build and Release tab, Select release definition PHP and click Edit

    release_def

  2. Go to Tasks and select Dev environment.

    dev_release

  3. Under Azure Resource Group Deployment task, update Azure subscription and Location.

    azure_sub

  4. Under Azure App Service Deploy task, update Azure subscription and click Save.

    azure_app_service

    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.

  1. Go to Code tab and navigate to the below path to edit the file.

    php/config.php

    code1

  2. Go to line number 11, modify PHP to DevOps for PHP using VSTS and commit the code.

    code_editing

  3. Go to Builds tab under Build and Release tab to see the associated CI build in progress.

    build

    in_progress_build

    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
  4. 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.

    Release in progress

  5. 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

    azure

  6. Select the App Service and from the Overview tab, click Browse to see the application deployed.

    website_php