|
| 1 | +[Azure App Service](../../overview.md) 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. |
| 2 | + |
| 3 | +You create the web app using the [Azure CLI](/cli/azure/get-started-with-azure-cli) in Cloud Shell, and you use Git to deploy sample PHP code to the web app. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +[!INCLUDE [quickstarts-free-trial-note](../../../../includes/quickstarts-free-trial-note.md)] |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +To complete this quickstart: |
| 14 | + |
| 15 | +* <a href="https://git-scm.com/" target="_blank">Install Git</a> |
| 16 | +* <a href="https://php.net/manual/install.php" target="_blank">Install PHP</a> |
| 17 | + |
| 18 | +## Download the sample locally |
| 19 | + |
| 20 | +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. |
| 21 | + |
| 22 | + ```bash |
| 23 | + git clone https://github.com/Azure-Samples/php-docs-hello-world |
| 24 | + cd php-docs-hello-world |
| 25 | + ``` |
| 26 | + |
| 27 | +1. Make sure the default branch is `main`. |
| 28 | + |
| 29 | + ```bash |
| 30 | + git branch -m main |
| 31 | + ``` |
| 32 | + |
| 33 | + > [!TIP] |
| 34 | + > 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`. |
| 35 | + |
| 36 | +## Run the app locally |
| 37 | +
|
| 38 | +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. |
| 39 | +
|
| 40 | + ```bash |
| 41 | + php -S localhost:8080 |
| 42 | + ``` |
| 43 | + |
| 44 | +1. Open a web browser, and navigate to the sample app at `http://localhost:8080`. |
| 45 | +
|
| 46 | + You see the **Hello World!** message from the sample app displayed in the page. |
| 47 | + |
| 48 | +  |
| 49 | + |
| 50 | +1. In your terminal window, press **Ctrl+C** to exit the web server. |
| 51 | +
|
| 52 | +[!INCLUDE [cloud-shell-try-it.md](../../../../includes/cloud-shell-try-it.md)] |
| 53 | +
|
| 54 | +[!INCLUDE [Configure deployment user](../../../../includes/configure-deployment-user.md)] |
| 55 | +
|
| 56 | +[!INCLUDE [Create resource group](../../../../includes/app-service-web-create-resource-group.md)] |
| 57 | +
|
| 58 | +[!INCLUDE [Create app service plan](../../../../includes/app-service-web-create-app-service-plan-linux.md)] |
| 59 | +
|
| 60 | +## Create a web app |
| 61 | +
|
| 62 | +1. In the Cloud Shell, create a web app in the `myAppServicePlan` App Service plan with the [`az webapp create`](/cli/azure/webapp#az_webapp_create) command. |
| 63 | +
|
| 64 | + 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`](/cli/azure/webapp#az_webapp_list_runtimes). |
| 65 | +
|
| 66 | + ```azurecli-interactive |
| 67 | + az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name <app-name> --runtime 'PHP|7.4' --deployment-local-git |
| 68 | + ``` |
| 69 | + |
| 70 | + When the web app has been created, the Azure CLI shows output similar to the following example: |
| 71 | +
|
| 72 | + <pre> |
| 73 | + Local git is configured with url of 'https://<username>@<app-name>.scm.azurewebsites.net/<app-name>.git' |
| 74 | + { |
| 75 | + "availabilityState": "Normal", |
| 76 | + "clientAffinityEnabled": true, |
| 77 | + "clientCertEnabled": false, |
| 78 | + "cloningInfo": null, |
| 79 | + "containerSize": 0, |
| 80 | + "dailyMemoryTimeQuota": 0, |
| 81 | + "defaultHostName": "<app-name>.azurewebsites.net", |
| 82 | + "enabled": true, |
| 83 | + < JSON data removed for brevity. > |
| 84 | + } |
| 85 | + </pre> |
| 86 | + |
| 87 | + You've created an empty new web app, with git deployment enabled. |
| 88 | + |
| 89 | + > [!NOTE] |
| 90 | + > The URL of the Git remote is shown in the `deploymentLocalGitUrl` property, with the format `https://<username>@<app-name>.scm.azurewebsites.net/<app-name>.git`. Save this URL as you need it later. |
| 91 | + > |
| 92 | + |
| 93 | +1. Browse to your newly created web app. Replace _<app-name>_ with your unique app name created in the prior step. |
| 94 | + |
| 95 | + ```bash |
| 96 | + http://<app-name>.azurewebsites.net |
| 97 | + ``` |
| 98 | + |
| 99 | + Here's what your new web app should look like: |
| 100 | +
|
| 101 | +  |
| 102 | +
|
| 103 | +[!INCLUDE [Push to Azure](../../../../includes/app-service-web-git-push-to-azure.md)] |
| 104 | +
|
| 105 | + <pre> |
| 106 | + Counting objects: 2, done. |
| 107 | + Delta compression using up to 4 threads. |
| 108 | + Compressing objects: 100% (2/2), done. |
| 109 | + Writing objects: 100% (2/2), 352 bytes | 0 bytes/s, done. |
| 110 | + Total 2 (delta 1), reused 0 (delta 0) |
| 111 | + remote: Updating branch 'main'. |
| 112 | + remote: Updating submodules. |
| 113 | + remote: Preparing deployment for commit id '25f18051e9'. |
| 114 | + remote: Generating deployment script. |
| 115 | + remote: Running deployment command... |
| 116 | + remote: Handling Basic Web Site deployment. |
| 117 | + remote: Kudu sync from: '/home/site/repository' to: '/home/site/wwwroot' |
| 118 | + remote: Copying file: '.gitignore' |
| 119 | + remote: Copying file: 'LICENSE' |
| 120 | + remote: Copying file: 'README.md' |
| 121 | + remote: Copying file: 'index.php' |
| 122 | + remote: Ignoring: .git |
| 123 | + remote: Finished successfully. |
| 124 | + remote: Running post deployment command(s)... |
| 125 | + remote: Deployment successful. |
| 126 | + To https://<app-name>.scm.azurewebsites.net/<app-name>.git |
| 127 | + cc39b1e..25f1805 main -> main |
| 128 | + </pre> |
| 129 | +
|
| 130 | +## Browse to the app |
| 131 | +
|
| 132 | +Browse to the deployed application using your web browser. |
| 133 | +
|
| 134 | +``` |
| 135 | +http://<app-name>.azurewebsites.net |
| 136 | +``` |
| 137 | +
|
| 138 | +The PHP sample code is running in an Azure App Service web app. |
| 139 | +
|
| 140 | + |
| 141 | +
|
| 142 | +**Congratulations!** You've deployed your first PHP app to App Service. |
| 143 | + |
| 144 | +## Update locally and redeploy the code |
| 145 | + |
| 146 | +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`: |
| 147 | + |
| 148 | + ```php |
| 149 | + echo "Hello Azure!"; |
| 150 | + ``` |
| 151 | + |
| 152 | +1. In the local terminal window, commit your changes in Git, and then push the code changes to Azure. |
| 153 | + |
| 154 | + ```bash |
| 155 | + git commit -am "updated output" |
| 156 | + git push azure main |
| 157 | + ``` |
| 158 | + |
| 159 | +1. Once deployment has completed, return to the browser window that opened during the **Browse to the app** step, and refresh the page. |
| 160 | + |
| 161 | +  |
| 162 | + |
| 163 | +## Manage your new Azure app |
| 164 | + |
| 165 | +1. Go to the <a href="https://portal.azure.com" target="_blank">Azure portal</a> to manage the web app you created. Search for and select **App Services**. |
| 166 | + |
| 167 | +  |
| 168 | + |
| 169 | +2. Select the name of your Azure app. |
| 170 | + |
| 171 | +  |
| 172 | + |
| 173 | + Your web app's **Overview** page will be displayed. Here, you can perform basic management tasks like **Browse**, **Stop**, **Restart**, and **Delete**. |
| 174 | +
|
| 175 | +  |
| 176 | +
|
| 177 | + The web app menu provides different options for configuring your app. |
| 178 | +
|
| 179 | +[!INCLUDE [cli-samples-clean-up](../../../../includes/cli-samples-clean-up.md)] |
| 180 | +
|
| 181 | +## Next steps |
| 182 | +
|
| 183 | +> [!div class="nextstepaction"] |
| 184 | +> [PHP with MySQL](../../tutorial-php-mysql-app.md) |
| 185 | +
|
| 186 | +> [!div class="nextstepaction"] |
| 187 | +> [Configure PHP app](../../configure-language-php.md) |
0 commit comments