For all those who wish to have a feel of what the cloud is like and how easy it is to implement a cloud based backend for your web application, this is exactly what you have to read.
When I was asked to develop a cloud based system for my University, I wasn’t even sure of what a “cloud-based” system is. I was absolutely new to Windows Azure. But it did not take me long to figure out how to create a backend for my web application on the cloud. And this step-by-step tutorial should make it easier for all those web designers out there to help you develop a backend for your web app in Windows Azure and connect to it using PHP.
A step-by-step demonstration of how to create a backend for your web application in the cloud using PHP:
1. Web Application Deployment:
Step 1: Login to Windows Azure (You need to have an account for this. If you don’t then you should definitely give it a try. Go for the 90 day free trial). On the dashboard click on New –> Compute –> Website –> Custom Create
Step 2: Enter a URL for the web application and choose a geographical location to store your data from the combo box. For database option choose Create a new SQL database. Enter a name for the connection string and click on next.
Step 3: Enter a name for the database and for server choose New SQL Database Server. Provide a login name and password, choose a region to store data and click on next to advance to the next step. Configure advance database settings by specifying the database size and press on the tick mark.
Step 4: The website should be visible in the list of websites. Click on the name of the website and click on WebMatrix to download WebMatrix software.
Step 5: Open WebMatrix. Click on New to open up a window to choose the file type to be created. This is where HTML and/or PHP pages are developed and can be uploaded.
Step 6: Once the code has been added, press on Run. The code is now updated and the webpage opens up.
2. Configuring the database in Windows Azure
Step 1: Login to Windows Azure. Click on the website to open the dashboard for the website. Click on Linked Resources to view the database created for the website.
Step 2: Click on the database to open up the dashboard for the database. Click on Manage and enter login details to login.
Step 3: Click on Create new table to create a new table in the database. Once the table is created click on Edit beside the table to add attributes and define their data types.
3. Accessing SQL Database from Web Application
Step 1: Login to Windows Azure. Click on the website name –> linked resources –> database name to open up the dashboard for the database. Click on Show connection strings to view the connection string to the database in ADO.NET, ODBC, PHP and JDBC.
Step 2: Using PHP code to connect – it is possible to connect to Windows Azure SQL database using the connection string as follows:
Step 3: The data can be manipulated by embedding T-SQL statements within the PHP code as follows: