Windows Azure - Getting Started With PHP

By Michael Kramer on October 3rd 2014 @ 8:12 am

I created a framework in PHP, called Beam With Joy. It follows the MVC Programming pattern and I’ve been using it for a few months now, expanding on it, and using it for a variety of projects, from CMS System, to Analytical Systems, to full advanced web applications.

I’ve been developing a web application which I cannot give all the details, but it needed to be able to handle millions upon millions of rows of data. The old BWJ framework used an Eager Load methodology, I had it pre-load almost all the information you could ever possibly need. While this works fantastic for small amounts of data, when you get into the hundreds of thousands, to millions of data rows, it is impossible to use.

I restructured the framework into lazy-loading, meaning only the data that needs to be displayed will be actively loaded. For example, if I have 259K user accounts, I will only be displaying a page of 20, and not load the others. For this I used the, I created JSON Rest Stores and linked it up, and now you can view quite easily a million + rows of data in a table, and it runs beautifully.

It turns out that Microsoft is interested in this project, and that it could one day be combined with an ongoing project they have been working on. In order for my side of things to connect with their side of things, I have to convert my project into a Windows Azure project.

Now, I am a .NET hater. I hate it absolutely, I think it is the worst programming language ever, so I was absolutely not thrilled when this news came about, however! Windows Azure not only supports PHP and Java (the 2 languages this particular application uses) but there was an extension for Eclipse to allow me to connect.

Setting up Eclipse

I had been using Eclipse for some time, I had all my wonderful plugins installed, Subversion support, Eclipse SQL, the PDT Plugin, etc. I followed the instructions on added the update site, waited…and alas! It broke, couldn’t find the dependencies. There was no support for this error anywhere, I spent many hours searching and trying things.How did I solve it? You need to download the exact version of Eclipse they are using. Eclipse Helios is not supported, I highly suggest those who want to use Azure for PHP development, download the Eclipse Build they suggest, which is Galileo

After I figured out that was the problem, I got the Azure plugin to install successfully! Yay! I did the hello world application, and ran it in the Windows Azure Development Fabric™ Which! Didn’t go so well. I finally tracked it down to a problem with IIS. I had followed the instructions to a T and still, couldn’t get it to go anywhere. Going to in my browser did nothing.

I thought this might be a problem with WAMP being installed as well, but since it wasn’t running couldn’t think of how that could be. I then noticed that in IIS, the Default Website wasn’t running. I right clicked it and told it to run. Nothing happened. The Problem, it turns out, after hours of searching, was Skype. When Skype is running, IIS doesn’t like to (at least for the first run). I closed Skype, re started the Default Website and voila! It started up no problem.

Using Eclipse with the Windows Azure plugin I was able to start my Hello Azure application and get it running.

Setting up SQL Azure

This application relies heavily on relational databases so the normal Table, Blob, etc that Azure offers as Data Storage wouldn’t suffice. Luckily! They have SQL Azure, which is a SQL Server in the cloud.

For this I had to register an Azure Account (thought I could get away with not having one for a while) But I wanted to make sure it worked in the cloud, so after that very easy process, I had it up and running, and created my first SQL Instance on the cloud.

Eclipse has a very handy way of handling SQL Azure, when you create a new project (or migrate a previous project) you can set it to support SQL Azure. I did this and it created a SQLAzureSample.php which contained all the information I needed to know. Essentially it asks you to right-click on the WebRoll and go to Properties, Go down to Windows Azure, and configure the SQL Connect information. This automatically creates a connect.php file in your root directory.

I had a small problem connecting with the database, it turns out your username needs to include @domain, so for example, siosphere@c62swz6k2ha and it worked wonderfully. I was able to click Test Connection and it connected fine.

I then saved it, uploaded my Application to the Development Fabric and….Nothing. Got an error that it could not connect to host. I opened up SQLAzureSample.php and located the connection line, and saw that it didn’t have any real error messaging. I tracked down the correct function which is sqlserv_errors(); and put that in there.


Turns out the error I was getting was that no Default Driver could be found. And in the error message it gave a link of where to get it, how convenient right? Wrong. The installer it downloaded opened up and then said that it wasn’t supported on this processor. So I tried searching all over Microsoft’s site to try to find the x64 version of this driver, but to no Avail.

I finally found a forum post that helped immensely and gave me a direct link to what I needed in the x64 Architecture. I have included these below:

X86 Package (sqlncli.msi) – 4504 KB

X64 Package (sqlncli.msi) – 7919 KB

IA64 Package (sqlncli.msi) – 11078 KB

After that was installed, and I submitted my application to go to the cloud, it worked and connected to the database flawlessly.

Now, I just need to update the full application to support this. So far I’ve gotten it to give me an 500 Error, so progress is coming.

comments powered by Disqus