DEV Community

Cover image for How to deploy a PHP app to Azure
Joe Steinbring
Joe Steinbring

Posted on • Updated on

How to deploy a PHP app to Azure

In a previous post, we covered how to deploy a Node.js app to Azure. This time, we are going to cover how to deploy a PHP app to Azure. Just like last time, we are going to be using the Azure CLI to do this.

Prerequisites: PHP and Azure CLI

Before we go any further, you need to have PHP installed. We can install it using Homebrew. PHP is what is going to allow you to test your code before deploying it to the server. You are also going to need to have Azure CLI installed on your computer.

Step 1: Create a PHP app to deploy

Our test app is going to be pretty simple, this time. It is just going to be echo "Hello Flavortown!";.

echo

If you want to test the app, you can run php -S localhost:8080 from the terminal.

php -S localhost:8080

With the PHP Development Server running, you can open http://localhost:8080/ in a browser.

http://localhost:8080/

Step 2: Deploy to Azure

From within the project folder, you can deploy the project by running az webapp up --runtime "PHP:8.0" --resource-group jsteinbring-demo-apps --name JWS-PHP-Example --os-type=linux.

az webapp up --runtime

At this point, you can visit https://jws-php-example.azurewebsites.net/ to see the end-result.

https://jws-php-example.azurewebsites.net/

Step 3: Redeploying to Azure

Similar to last time, the details for the project are stored within .azure/config, so running az webapp up --runtime "PHP:8.0" --os-type=linux from the project folder should update what we have on the server.

.azure/config

If we update the index.php file ...

echo

... and then run az webapp up --runtime "PHP:8.0" --os-type=linux ...

az webapp up --runtime

... the app should deploy.

https://jws-php-example.azurewebsites.net/

Unlike last time, with PHP we do need to specify the runtime when updating the application. The process is pretty similar, though.

Have any questions, comments, or concerns? See something that I am doing wrong here? Please feel free to drop a comment, below.

[ Cover photo by Vishnu R Nair on Unsplash ]

Top comments (0)