0 Shares 705 Views

How to Create an Azure Mobile App using PHP

Aiesha Hasan Jul 17, 2017
how-to-create-an-azure-mobile-app-using-php

Bringing you here, the most demanding tutorial as how to create PHP web app in Azure. Azure web apps gives highly scalable and self-patching web hosting service. In this tutorial you will learn how to deploy a PHP app to Azure web apps. We’ll be creating the web app using Azure CLI and will use GIT to deploy the sample PHP code to the web app.

The below steps can be used in Mac, Linux, and Windows. Once the essential requirements such as PHP and GIT are installed, it will take about five minutes to complete all the steps.

Get Free Help From Professional PHP Development Company.

You can create a free Azure account if don’t have the Azure subscription before beginning.

Launch Azure Cloud Shell.

The Azure cloud shell is a free bash shell which can be run directly within the Azure account. It has Azure CLI already installed in it and configured so that can be use with your account. Click on the Cloud Shell button on the upper right of the Azure portal in the menu.

cloud-shell-menu

The button will launch an interactive shell which can be use to run all the steps told in this topic.

cloud-shell-safari

Run az –version to find the version of the CLI you are using.

Download the Sample

In the terminal window, run these following commands to copy the sample app repository to the local machine.

git clone https://github.com/Azure-Samples/php-docs-hello-world

Now change to the directory that contains the sample code.

cd php-docs-hello-world

Run the App Locally.

First run the application locally by opening terminal window and use the PHP command to launch the pre-built PHP web server.

php -S localhost:8080

Open up any web browser and type  the following local host address http://localhost:8080.

You will see a HELLO WORLD message displayed on the screen from the sample app.

Exit the web server by pressing Ctrl+c

Log in to Azure

Use the Azure CLI 2.0 to create the resources required to host the app in Azure. Log in to the Azure subscription by the AZ login command and follow the directions displayed on the screen.

az login

Configure a deployment user

With the AZ web app deployment user command, create the deployment credentials.

A deployment user is necessary for FTP and Local GIT deployment. The use name and password will be different from the Azure subscriptions credentials.

az webapp deployment user set –user-name <username> –password <password>

Replace the username and password with new one. The name must be unique and the password must be eight characters long.

It is a one time process and the deployment user created can be used for all Azure deployments.

Create a Resource Group

With the AZ group create command, create a resource group.

A resource group is actually a container which posses Azure resources such as web apps, databases and stored accounts to manage and deploy.

az group create –name myResourceGroup –location westeurope

Create the resource by following the above example.

Generally the resources created in a region near you. Run the az appservice list-location command to see the supported locations for the Azure web app.

Create an Azure App Service Plan

With the az appservice plan create command, create an azure app service.

The app service plan specifies the location, features and size of the web server.

App Service plans define:

  • Region (for example: North Europe, East US, or Southeast Asia)
  • Instance size (small, medium, or large)
  • Scale count (1 to 20 instances)
  • SKU (Free, Shared, Basic, Standard, or Premium)

The below example creates an app service plan in free pricing.

az appservice plan create –name myAppServicePlan –resource-group myResourceGroup –sku FREE

After the app service plan be created, the AZURE CLI will show some information like this

 

Create a Web App

With the AZ webapp create command, create a web app in the app service plan.

The web app will provide a hosting space for the code and a URL to view the deployed app.

az webapp create –name <app_name> –resource-group myResourceGroup –plan myAppServicePlan

In the above command, replace the app name with some unique name.

Once the web app is created, the Azure CLI will show below information.

 

Type the following address on any browser to check your newly created web app.

http://<app_name>.azurewebsites.net

app-service-web-service-created

A web app in Azure has been created.

Configure local GIT Deployment

With the az webapp deployment source configuration-git command, configure local Git deployment to the web app.

For quickstart, deploy by using local Git. To deploy content to web app, app service supports offers several ways such as FTP, Local Git, GitHub and  Bitbucket

az webapp deployment source config-local-git –name <app_name> –resource-group myResourceGroup –query url –output tsv

Replace app name with the web app’s name in the above command.

The output format will be :

https://<username>@<app_name>.scm.azurewebsites.net:443/<app_name>.git

The username is the deployment username which you have created previously. Save the above URL to use in the next steps.

Push to Azure from Git

git remote add azure <URI from previous step>

Add remote Azure to the local GIT repository,

Push to the Azure remote to deploy the app. Ensures the password you entered is the deployment user password not the password you used to log in to the Azure portal.

git push azure master

The above command will display following information.

 

Browse to the App

Type the below URL to browse the deployed application on any web browser.

http://<app_name>.azurewebsites.net

hello-world-in-browser

Congratulations! you have deployed the PHP app to App service.

Aiesha Hasan

Aiesha Hasan

Digital Content Producer at Arpatech
Aiesha Hasan is a Web Developer and a Digital Content Creator. She likes to keep in touch with the latest technology in the world and educate people about it.
Aiesha Hasan

Latest posts by Aiesha Hasan (see all)