How to deploy a PHP app to Azure
Tags: php, azure, tutorial
Published: 2022-09-27 11:56:58

In a previous post, we covered [how to deploy a Node.js app to Azure](https://dev.to/steinbring/how-to-deploy-a-nodejs-app-to-azure-an0).  This time, we are going to cover how to deploy a [PHP](https://jws.news/tag/php/) app to Azure.  Just like last time, we are going to be using the [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) to do this.

## Prerequisites: PHP and Azure CLI

Before we go any further, you need to have [PHP](https://formulae.brew.sh/formula/php#default) installed.  We can install it using [Homebrew](https://brew.sh/).  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](https://docs.microsoft.com/en-us/cli/azure/install-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 "Hello Flavortown!";](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ervxn8ibksmretey3s4.png)

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

![php -S localhost:8080](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6cnfqf8k2i7u6sm9tqt.png)

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

![http://localhost:8080/](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/105ti4hhzj1r67chlo9d.png)

## 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 "PHP:8.0" --resource-group jsteinbring-demo-apps --name JWS-PHP-Example --os-type=linux](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zyxxkzetkdvulexjm23a.png)

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

![https://jws-php-example.azurewebsites.net/](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7l5t44wcq6pnj5e0y3cq.png)

## Step 3: Redeploying to Azure

Similar to [last time](https://dev.to/steinbring/how-to-deploy-a-nodejs-app-to-azure-an0), 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y0uwpubvpy5kvbld0tgd.png)

If we update the index.php file ...

![echo "Hello Margaritaville!";](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/csgu316p8fhxjuvv17ua.png)

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

![az webapp up --runtime "PHP:8.0" --os-type=linux](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i10wwq8agegia859it9l.png)

... the app should deploy.

[![https://jws-php-example.azurewebsites.net/](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aikv9fbd7hk2w7ld7qfq.png)](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](https://unsplash.com/@vishnurnair?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/hacking?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) ]