Hello World from Azure

An introduction of running a Hello World example with PHP on Microsoft Azure Web App Service

Let me start with a “Hello World” example in PHP and put it on Microsoft Azure.

Hello World in PHP

I start with a file called “index.php” as it will be our entry point for web requests. In that file I write the following code:

<?php 
$helloWorld = "Hello World from Azure!";
?>
<html>
<head>
<title><?php echo $helloWorld ?></title>
</head>
<body>
<h1><?php echo $helloWorld ?></h1>
</body>
</html>

Because I saved this code in a file I can use the build-in web server from PHP to verify this code does what I expect it to do.

php -S localhost:8080 index.php

When I point my browser to http://localhost:8080/ I see the Hello World example.

This quick check confirms that my page works. I now want to publish this page on Azure.

Sign up for an Azure account

If you don’t have an Azure account yet, create one. Look at my post Create a free Azure account for details on what to expect and a step-by-step guide to create a free account.

Create an App Service in Azure

Azure App Services are fully managed platform by Microsoft for building, deploying and scaling your web applications. It’s a “Platform as a Service” or PaaS where you need to focus on your own code while Microsoft takes care of the platform and infrastructure underneath.

I assume that you already have an Azure account if you want to follow along.

Step 1: Create a resource group

The first step is to create a “Resource Group” which is a logical grouping of applications and services, similar as a project root folder. Here we will create all components that are required for running our example.

In this example I create a resource group “AzurePHPRG” and this will be the main resource group throughout most of the examples on this blog.

Step 2: Create an App Service

Within our resource group we’re going to create a new App Service that will host our Hello World example.

Once the web app is created and running, it doesn’t have our code yet. There are many ways to get your code onto the app service which I will discuss in more detail in other blog articles. For this example I will use the build-in Kudu directory editor.

After saving this code, I can point my browser to php-helloworld-from-azure.azurewebsites.net to see the result of my work.

This is just an introduction to running PHP applications on Azure. Next articles will cover how to connect with a Azure Databases for MySQL and how to secure your secrets with Azure Key Vault.

Tutorial video: Hello World from Azure with PHP
Michelangelo
Michelangelo

Passionate PHP developer, architect and community leader with nearly 20 years of experience in developing, modernizing and improving quality of complex PHP applications for enterprise, government, SMB and start-up markets.

Articles: 8

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.