Skip to content

Latest commit

 

History

History
180 lines (120 loc) · 7.14 KB

File metadata and controls

180 lines (120 loc) · 7.14 KB
ms.custom linux-related-content
ms.service azure-app-service

[!INCLUDE php-eol-notice]

Azure App Service provides a highly scalable, self-patching web hosting service. This quickstart tutorial shows how to deploy a PHP app to Azure App Service on Windows.

You create the web app using the Azure CLI in Cloud Shell, and you use Git to deploy sample PHP code to the web app.

Sample app running in Azure

You can follow the steps here using a Mac, Windows, or Linux machine. Once the prerequisites are installed, it takes about five minutes to complete the steps.

[!INCLUDE quickstarts-free-trial-note]

Prerequisites

To complete this quickstart:

Download the sample locally

  1. In a terminal window, run the following commands. It will clone the sample application to your local machine, and navigate to the directory containing the sample code.

    git clone https://github.com/Azure-Samples/php-docs-hello-world
    cd php-docs-hello-world
  2. Make sure the default branch is main.

    git branch -m main

    [!TIP] The branch name change isn't required by App Service. However, since many repositories are changing their default branch to main, this quickstart also shows you how to deploy a repository from main.

Run the app locally

  1. Run the application locally so that you see how it should look when you deploy it to Azure. Open a terminal window and use the php command to launch the built-in PHP web server.

    php -S localhost:8080
  2. Open a web browser, and navigate to the sample app at http://localhost:8080.

    You see the Hello World! message from the sample app displayed in the page.

    Sample app running locally

  3. In your terminal window, press Ctrl+C to exit the web server.

[!INCLUDE cloud-shell-try-it.md]

[!INCLUDE Configure deployment user]

[!INCLUDE Create resource group]

[!INCLUDE Create app service plan]

Create a web app

  1. In the Cloud Shell, create a web app in the myAppServicePlan App Service plan with the az webapp create command.

    In the following example, replace <app-name> with a globally unique app name (valid characters are a-z, 0-9, and -). The runtime is set to PHP|7.4. To see all supported runtimes, run az webapp list-runtimes.

    az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name <app-name> --runtime 'PHP|8.1' --deployment-local-git
    

    When the web app has been created, the Azure CLI shows output similar to the following example:

     Local git is configured with url of <URL>
     {
       "availabilityState": "Normal",
       "clientAffinityEnabled": true,
       "clientCertEnabled": false,
       "cloningInfo": null,
       "containerSize": 0,
       "dailyMemoryTimeQuota": 0,
       "defaultHostName": "<app-name>.azurewebsites.net",
       "enabled": true,
       < JSON data removed for brevity. >
     }
     

    You've created an empty new web app, with git deployment enabled.

    [!NOTE] The URL of the Git remote is shown in the deploymentLocalGitUrl property. Save this URL as you need it later.

  2. Browse to your newly created web app.

    Here's what your new web app should look like:

    Empty web app page

[!INCLUDE Push to Azure]

  Counting objects: 2, done.
  Delta compression using up to 4 threads.
  Compressing objects: 100% (2/2), done.
  Writing objects: 100% (2/2), 352 bytes | 0 bytes/s, done.
  Total 2 (delta 1), reused 0 (delta 0)
  remote: Updating branch 'main'.
  remote: Updating submodules.
  remote: Preparing deployment for commit id '25f18051e9'.
  remote: Generating deployment script.
  remote: Running deployment command...
  remote: Handling Basic Web Site deployment.
  remote: Kudu sync from: '/home/site/repository' to: '/home/site/wwwroot'
  remote: Copying file: '.gitignore'
  remote: Copying file: 'LICENSE'
  remote: Copying file: 'README.md'
  remote: Copying file: 'index.php'
  remote: Ignoring: .git
  remote: Finished successfully.
  remote: Running post deployment command(s)...
  remote: Deployment successful.
  To <URL>
      cc39b1e..25f1805  main -> main
  

Browse to the app

Browse to the deployed application using your web browser.

The PHP sample code is running in an Azure App Service web app.

Sample app running in Azure

Congratulations! You've deployed your first PHP app to App Service.

Update locally and redeploy the code

  1. Using a local text editor, open the index.php file within the PHP app, and make a small change to the text within the string next to echo:

    echo "Hello Azure!";
  2. In the local terminal window, commit your changes in Git, and then push the code changes to Azure.

    git commit -am "updated output"
    git push azure main
  3. Once deployment has completed, return to the browser window that opened during the Browse to the app step, and refresh the page.

    Updated sample app running in Azure

Manage your new Azure app

  1. Go to the Azure portal to manage the web app you created. Search for and select App Services.

    Search for App Services, Azure portal, create PHP web app

  2. Select the name of your Azure app.

    Portal navigation to Azure app

    Your web app's Overview page will be displayed. Here, you can perform basic management tasks like Browse, Stop, Restart, and Delete.

    App Service page in Azure portal

    The web app menu provides different options for configuring your app.

[!INCLUDE cli-samples-clean-up]