Getting started with PHP on Azure

Hello Everyone, today let’s make ourselves ready to learn a new topic i.e. hosting PHP application on Azure. Many of us must have came across the word Azure and some of us must be knowing how to host the application written in PHP on it. Today we will go over how to host the application on Azure and how to auto-deploy the code through bitbucket. So, why to wait !! Lets start then :).

In this blog, we will mainly come across these following words.
1. PHP
2. Microsoft Azure
3. Bitbucket

1. PHP :-

“PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language.” – wiki

Chicago Manual of Style, content style guide
The word PHP i.e. Hypertext Preprocessor earlier called as Personal Home Page. In 1994, Rasmus Lerdorf created this pretty language and in 1995, it came into existence as an open source technology. Because of its simplicity (as most of the syntax resembles to C, C++, Java), it is much popular in web development market and among the developers. One can take 100% advantage of using this language to make dynamic web pages quickly. It is a server side scripting language. Server side, as the name suggests, it runs on a web server and it requires a web browser to send/receive request/response. Scripting language, as the name suggests, it is only compiled when an interpreter reads it and convert it into machine understandable language.

But, first and foremost thing why developers love this technology is easy to learn, free of cost, platform independent and secure.

2. Microsoft Azure :-

“Microsoft Azure is a cloud computing platform and infrastructure created by Microsoft for building, deploying, and managing applications and services through a global network of Microsoft-managed data centers.” – wiki

Chicago Manual of Style, content style guide
The name Azure suggests, bright blue in colour like a cloudless sky. But in our context, this is little different :D. It is a platform which provides PaaS (Platform as a Service) and IaaS (Infrastructure as a Service) categories of cloud computing services. It supports many different programming languages including Microsoft and non-Microsoft related technologies. Azure was launched on 1st February 2010 as Windows Azure and then acquired the name as Microsoft Azure on 25th March 2014.

It is easy to publish and manage websites with PaaS environment. Mostly used for cloud computing, which literally means of using network to manage data, process and store which is hosted on remote servers rather than a local or personal server.

3. Bitbucket :-

“Bitbucket is a web-based hosting service for projects that use either the Mercurial (since launch) or Git (since October 2011) revision control systems.” – wiki

Chicago Manual of Style, content style guide
I hope everyone here are familiar with GIT, the version control system which is used for data integrity and support for distributed workflows. It is used to manage source code and the name satisfies as SCM, Source Code Management.

Bitbucket is the solution for professional teams who uses GIT. It offers hosting source code in free of cost and it has the option to add wikis for project & option to track issues. It is similar to Github which is used to manage the code for a distributed application.

Now, let’s start with setting up and host a PHP application on Azure.

Step 1 :- First, we need to login into the account on Azure Portal. For that, we need to provide work or school or personal Microsoft account, otherwise need to create a new Microsoft account without any cost.

Once you successfully logged in into the system, it will redirect into Azure Portal page. See the below image for reference.

Screen Shot 2016-05-14 at 10.18.31 PM

Step 2 :- Now, click on All Resources -> New button for creating the base/marketplace.

Screen Shot 2016-05-14 at 11.22.49 PM

Then select Web App + MySQL for hosting the application. Click on Create button for creating the hosting setup.

Screen Shot 2016-05-14 at 11.24.06 PM

Step 3 :- Once you click on Create button, it will open one form to provide App Name, Subscription Details, Resource Group, Database Details and Legal Terms to accept. Provide a unique App Name as the website hosting name would be app_name.azurewebsites.net and the DB details (choose Database pricing tier as Mercury, the free one) as like below.

screen-shot-2016-05-14-at-11-25-18-pm

screen-shot-2016-05-14-at-11-27-15-pm

screen-shot-2016-05-15-at-1-01-44-am1

Step 4 :- Once you provide every information mentioned above, check Pin to dashboard option and click on Create. Now, it will start the process of deployment the server and it may take few time to complete the process.

submitting_deployment

Screen Shot 2016-05-16 at 12.33.44 PM

Step 5 :- Now lets go to Bitbucket (https://bitbucket.org/) and create the account. Do the Signup here (https://bitbucket.org/account/signup/) and you can see the Dashboard like the below once you successfully logged in into the system.

screen-shot-2016-05-16-at-12-45-25-pm

Step 6 :- Inside Bitbucket, go to Repositories -> Create Repository. Provide the necessary details there like below :
Screen Shot 2016-05-16 at 12.53.14 PM

Once you Create Repository, it will show the dashboard for Repository setup and then select “I’m starting from scratch”.

screen-shot-2016-05-16-at-12-57-01-pm

Step 7 :- Open your Terminal to run some commands. Follow the rules mentioned in the above section i.e. “Set up your local directory”, “Create your first file, commit, and push”. For reference, do the following :

Set up Git on your machine if you haven’t already

Create your first file, commit, and push

  • phpinfo() >> phpinfo.php
  • git add phpinfo.php
  • git commit -m ‘Initial commit with phpinfo’
  • git push -u origin master

Step 8 :- Now time is to connect Azure with the deployment source for continuous integration. Again lets go to https://portal.azure.com and click on All Resources. Select the app we have created so far i.e. test-demo-app (type as App Service) and then choose Deployment Source from PUBLISHING section like below.

screen-shot-2016-05-16-at-1-23-33-pm

Step 9 :-

Click on Choose Source and select Bitbucket as the source. Provide the Authorization details of Bitbucket. Once Authorization is completed, it will ask to choose Project and branch. Provide all the details like below.

Screen Shot 2016-05-16 at 1.32.54 PM

Step 10 :- After providing the details and click on OK will start the source deployment and finally it will show one flash message as Successfully set up deployment source.

We are all DONE !!! 🙂 Now browse http://test-demo-app.azurewebsites.net/ (as we have provided the name as test-demo-app so far) and you can view the current PHP information for your server now.

Isn’t it cool & easy !!! 🙂 So, why to wait? Create one simple PHP page and host the application into Azure along with continuous integration using git Bitbucket. Do you really find it useful? If yes, then please like and add some comments, if you want.

Thanks and I will be happy to hear from you 🙂 :).