| 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.
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]
To complete this quickstart:
-
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 -
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 frommain.
-
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
phpcommand to launch the built-in PHP web server.php -S localhost:8080
-
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.
-
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]
-
In the Cloud Shell, create a web app in the
myAppServicePlanApp Service plan with theaz webapp createcommand.In the following example, replace
<app-name>with a globally unique app name (valid characters area-z,0-9, and-). The runtime is set toPHP|7.4. To see all supported runtimes, runaz webapp list-runtimes.az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name <app-name> --runtime 'PHP|8.1' --deployment-local-gitWhen 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
deploymentLocalGitUrlproperty. Save this URL as you need it later. -
Browse to your newly created web app.
Here's what your new web app should look like:
[!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 deployed application using your web browser.
The PHP sample code is running in an Azure App Service web app.
Congratulations! You've deployed your first PHP app to App Service.
-
Using a local text editor, open the
index.phpfile within the PHP app, and make a small change to the text within the string next toecho:echo "Hello Azure!";
-
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 -
Once deployment has completed, return to the browser window that opened during the Browse to the app step, and refresh the page.
-
Go to the Azure portal to manage the web app you created. Search for and select App Services.
-
Select the name of your Azure app.
Your web app's Overview page will be displayed. Here, you can perform basic management tasks like Browse, Stop, Restart, and Delete.
The web app menu provides different options for configuring your app.
[!INCLUDE cli-samples-clean-up]






