Easy Setup for PHP On Azure Development
Join the DZone community and get the full member experience.Join For Free
In this post, I will cover the Windows Azure 4 Eclipse tooling setup.
There are two major things that we need to do. First is to get the Windows Azure SDK installed. The reality is that this is all that you *really* need to do Windows Azure development and testing. However, we want to do our PHP development with the Eclipse toolset for Azure. This gives us debugging support and a lot of great helpers.
Installing the Windows Azure 1.1 November 2010 SDK
First, we need to get the requirements for the Windows Azure 1.1 November SDK itself installed.
To get started, we need to have Windows Vista with Service Pack 1 or later. Really, I recommend that you go with Windows 7 if you have to upgrade.
The next thing that you need is to enable IIS with ASP.NET and CGI support. This is easier than it might seem. In the Control Panel, find “Turn Windows Features on or off”. On Vista, you might have to open Add/Remove Programs to find that option. Here, you need to navigate down the tree and find Internet Information Services | World Wide Web Service | Application Development Features and enable ASP.NET and CGI. That will auto select the other dependencies such as .NET Extensibility and ISAPI Extensions and Filters.
Once you complete that, you need to install some version of SQL Server 2005 or later. The one that I recommend, if you don’t have SQL Server already installed is Microsoft SQL Server 2008 Express.
Those are all of requirements the Windows Azure 1.1 November 2010 SDK. At this point we can download and install it.
Installing Eclipse with the Windows Azure for Eclipse tooling
The next step is to install Eclipse itself. Eclipse is written in Java so you will need the Java JRE 5 or later. 5 is no longer supported so I recommend that you go with Java JRE Standard Edition Version 6.
Once that’s installed, it’s a simple matter of downloading the PDT 2.1 All In Ones / Eclipse PHP Package and unzipping it into a folder. The PDT version of Eclipse comes with a lot of tools for PHP including perspectives for PHP, the Zend debugger, XDebug, syntax highlighting and more. The Windows Azure 4 Eclipse tooling builds on this.
Now, you need to install the Windows Azure 4 Eclipse tooling. To do that, open Eclipse and select Help | Install New Software. Click “Add” and put in Windows Azure For Eclipse for the title and http://www.windowsazure4e.org/update for the location. In the tree below, select all three pieces and follow the rest of the wizard.
This installs the Windows Azure for PHP SDK and a lot of tooling inside of Eclipse to get you set up.
At this point, you are technically ready to go but I recommend doing a few more things.
Quick Tips to Make Things Smoother
There are a number of little things that we discovered throughout the week that will make things easier for you.
PHP Version Conflicts
The first thing to do is to check to see if you’re going to have any conflicts between the version of PHP on your disk and the version of PHP that comes with the Eclipse tooling. The conflict is that even if both versions are PHP 5.2.13, the version that Eclipse uses is the thread-safe version and the one that everyone else in the world uses is the non-thread-safe version because most people don’t do threading in PHP anyways (I know you do Liz Smith but you’re not most people…). This happens if you’ve used the PHP Installer or the Web Platform Installer to get PHP on your box because both of them put PHP in the %Path% which is the right thing to do. The issue comes in when the Azure DevFabric starts PHP-CGI.exe from your Azure install but that executable looks in the path for it’s dependencies. It finds the non-thread-safe libraries and throws an exception. Oops.
*update* I had a much better idea than the below – check out my new post on resolving the PHP Version conflicts at Resolving PHP Version Conflicts While Developing For Azure”
There are a couple of fixes
that you could leverage, none of which are ideal. One is to just
install the thread-safe version on your box. There are two issues here.
First is that you are now using the thread-safe version of PHP on your
own box and it might not be that one in the cloud. The second issue is
that you are using your php.ini file from the c:\Program Files
(x86)\PHP\ folder. This is not really an issue if you remember this fact
and make sure that you deploy that PHP.ini file and set of extensions
that you want to deploy. The other fix, the one that
I’ve chosen to do most of the time, is to simply rename the PHP
directory on my disk (typically at c:\Program Files\PHP or c:\Program
Files (x86)\PHP) when I’m doing Azure development and rename it back
when I want to do local development. This is a little bit of a pain
sometimes but it’s easier to find these issues than the subtle ones that
could be introduced by the other technique.
Resolving the mystery 500 Error
Unfortunately, there’s not a great way to divine what is causing the 500 error in some cases. The one that I see most often is the PHP version conflict. Others include database connection errors, file permissions issues, uncaught exceptions and the like. There are two ways to handle this.
The first is to make heavy use of the logging facilities to write out to the dev fabric manager’s UI the exception.
The second way is to attach either the Zend debugger or XDebug to the Dev Fabric and step through the issue. The way to do that is to
Zend Debugger and Windows Azure DevFabric Storage
The first thing is that the Windows Azure DevFabric Storage uses port 10000. This is not a bad thing except that the Zend Debugger, by default, also uses port 10000. The end result is if you launch Eclipse and then try to start the development fabric storage engine, you’ll get a conflict.
Specifically, the error is from the Development Storage engine – “The process cannot access the file because it is being used by another process”. This is a bizarre error that doesn’t actually give you correct information. The way to fix this is in Eclipse, go to Windows | Preferences, find the Zend Debugger settings and edit the port.
Download Windows Azure for PHP Contrib Project
There are a couple of things that are not in the Windows Azure for PHP SDK. A couple of specific examples are Azure Drives, editing the PHP.ini and more. That’s all found in the Windows Azure for PHP Contrib project by Maarten Balliauw. Fun story on this is that at JumpIn Camp Maarten looked over at me and asked me if there was a way to mount Azure drives in PHP. I said that I didn’t think so. 20 minutes later, he called me over to show me that he had gotten it working. He spent another 20 minutes cleaning it up and committed his patch to the Windows Azure for PHP Contrib
Creating a Hello World Azure Application with Eclipse
This has walked you through the setup of the Windows Azure 4 Eclipse tooling and now you’re ready to get started with your first Azure application to test the install and all.
To test the install, click File | New | Project. In the New Project Wizard, expand the tree to find PHP | Windows Azure Web Project.
In the PHP Azure Project, name the project Hello World and select the Windows Azure Data Storage option.
This will create the project and give you some starter code that you can work with. To do that, select the project in the PHP Explorer and select from the menu Windows Azure | Run in Development Fabric. This will package the application and then launch it in the DevFabric. If it’s not running, it will give you the user access control admin permissions screen twice, once for the DevFabric Compute and once for the DevFabric Storage.
Next will launch the browser and navigate to your application running in the DevFabric. The simple Hello World show PHPInfo().
Soon, I’ll post about writing a slightly more complex application.
Please use the comments on this post to let me know if you were successful or not in getting the PHPInfo() to show…
Opinions expressed by DZone contributors are their own.