Running PHP on Windows Azure in the Cloud
Richard Campbell and Carl Franklin chat with Cory Fowler, a Microsoft MVP for Windows Azure, who provides insights into running open source PHP web applications on Azure in the cloud.
March 7, 2012
Editor's note: Welcome to .NETRocks Conversations, excerpts from the .NET Rocks! weekly Internet audio talk show. Hosts Richard Campbell and CarlFranklin chat with a wide variety of .NET developer experts. This month's excerpt is from show 651, with Cory Fowler, a Microsoft MVP for WindowsAzure, who discusses his experience running open source PHP web applications on Azure in the cloud.
Carl Franklin:Our guest is Cory Fowler. Cory refers to himself as a "Developer as a Service." I kind of like that. Welcome to the show, Cory.
Cory Fowler:Thanks for having me on.
Franklin:We understand that you do quite a bit in the cloud with PHP.
Richard Campbelland Carl Franklin (both Microsoft Regional Directors) are the voices and brains behind .NET Rocks! (www.dotnetrocks.com). Theyinterview experts to bring you insights into .NET technology and the state of software development. They're more than dry technical interviewers-theyhave fun!
Fowler:Yeah, I've been starting to play around a lot with PHP on Windows Azure. It's one of the areas that no one is really focusing on right now, and I thinkopen source should really have more of a focus in the cloud even on the Microsoft stack.
Franklin:It's open source software, even running on Linux and Linux servers, in the cloud. Isn't that pretty prevalent?
Fowler:Yeah. Open source is really dominant on Amazon Web Services, more so than Azure.
Franklin:Yeah.
Fowler:But Microsoft has done a really great job of allowing people to run PHP, Ruby, Python, and even Java on Azure, and they're trying to make it a lotbetter for people to move over to the Windows Azure platform.
Franklin:What kinds of applications are you running on Azure in PHP?
Fowler:Right now I'm mostly just using WordPress on Azure. I'm starting to look at a couple of different applications that were kind of using PHP [as well as]trying to migrate a couple of people from their existing PHP application onto Azure just to get them into the cloud computing area.
Richard Campbell:It strikes me that that's the main reason to run PHP in that scenario. It's the code bases available to use, particularly WordPress.
Fowler:Yeah.
Franklin:Right, but all sorts of other blogs and portals as well.
Campbell:What are you using for a data store with WordPress?
Fowler:Right now I'm using the SQL Azure back end, using the SQL Server driver for...
Campbell:For WordPress?
Fowler:Well, not for WordPress. It's just the SQL Server driver for PHP.
Campbell:Oh, OK.
Fowler:And that allows the connectivity between SQL Azure and PHP.
Campbell:So that makes it definitely a hybrid because typically you think PHP with MySQL.
Franklin:Yeah. And there is a solution to run MySQL in the cloud, but it doesn't really seem like a full-time scenario. There are a lot of things you need toworry about, like failover. If you want to run multiple databases in the back end, there's a lot of synchronization code that you have to run to makesure that your master and secondary databases are always synced up together.
Franklin:What is the install experience for PHP on Azure? Are there any gotchas there?
Fowler:There are a couple of gotchas. [First,] before the Web Platform Installer had a command-line tool-which is what I'm using now, you basically had toupload the entire PHP application within your solutions and then post that to Azure, and then Azure would handle running the fast CGI plug-in in thebackground. Now you can actually go ahead and, using a start-up task, run the WebPI [Microsoft Web Platform Installer] command-line tool and basicallyinstall PHP. Now PHP 5.2 works really well when you're installing it. It was a very quick, simple process. You just start up the executable when yourstart-up task runs. But PHP 5.3 had a couple of dependencies, and there's actually a dialog box that would have popped up.
Franklin:Oh. Yuck.
Fowler:Now in the start-up class in the cloud, there's no one there to kind of hide any kind of dialog boxes that pop up. If a dialog box is open in thecloud, and no one is around to click it, is it really there? And basically, you have to try and find a work around for that. So the team for WebPI wentin and added an accept an end-user license agreement command-line switch, and basically that would take care of any dialog boxes that pop up during theinstallation using WebPI.
Franklin:Whoa.
Campbell:Gee, I remember that we have dealt with these issues with Windows Server boxes where anything that will pop up as a dialog went to the event handlers,so that it would just show up as an event entry in the error logs.
Franklin:I have gotten the thing on Windows Server, Richard, where you right-click something. You know you are running remote access, you right-click to selectRun as Administrator, and the dialog box pops up somewhere else, and then you're locked. Yeah, I've had that problem. But you know, generally, thatpopping up a dialog box in a web app-hmm, not a good idea... or anything that's going to run on the server, any install that's going to run on theserver. I hate that.
Fowler:Yes.
Campbell:I'm just surprised that you actually will get that Windows in Azure to be able to actually do that. You know, I thought all of this was isolated fromus, that we couldn't touch the Windows part of Azure at all.
Fowler:Yeah. Windows is relatively isolated. You can do a lot of modifications using start-up tasks. I wrote a blog post on how to use PowerShell scriptswithin a start-up task, and basically, you have to change the execution policy, and then you can actually start executing PowerShell scripts back andstart manipulating Windows. The biggest thing and the reason why [Microsoft] kind of said that you don't really have access to the underlying OS isthat there is no real persistence there. So if you go and start fiddling around a lot, unless it's part of your start-up process and it runs everysingle time that your instance restarts, it gets lost if your instance goes down for any reason.
Campbell:So anything you can plug into the start-up process gets saved as part of a configuration. So when you fire up new instances, you get all that stuff.But actual configuration inside of Azure is that everything is temporary.
Fowler:Yeah. Like you can actually go and remote test up into your Azure instance, and you can start fiddling around there and changing settings andeverything. But if it comes time to either upgrade your role to a new version of the guest OS, or if the machine fails or whatever and your instancecomes down and gets moved over to another machine, then any of those settings that you set when you're doing RDP have now been lost.
Franklin:Let's talk about those, you know, the dependency that popped up this dialog in the first place. I imagine that's going to be a common experience withanyone installing open source or ported software from, you know, onto Azure or into any platform that's a port. What kinds of dependencies are there,and has that been a constant problem, or is that just [something that] comes with the territory?
Fowler:It comes with the territory. I would say that a lot of installers nowadays, if there is a command-line install for it, they have the quiet installswitch, or you just kind of say that's OK, I'm not going to pop up any dialog because there isn't anyone sitting here checking up on the installprocess. So anything that you can do along those lines that has a quiet installer, it's good. You can push that into a start-up task without anyissues. It comes to the point where you get that one application that you absolutely need for your app in the cloud, and there is no quiet installer oranything along those lines.
Franklin:Yeah.
Fowler:And that is where you start getting into the VM role because you have to set up one major dependency for your application, and there isn't a quietinstaller for that scenario.
Campbell:Where did the Web Platform Installer come into this? Is that where you got PHP from?
Fowler:Yeah. So I started doing the installation process with PowerShell. I basically went in, remotely connected it with WebClient to PHP.NET, downloaded theinstall package, figured out how to unzip it, and I was working on doing that as a deployment model. And then I did a quick Bing search for setting upPHP, and I noticed that the Web Platform Installer actually uses that functionality. So I started to think, what if I can just download the WebPlatform Installer and then allow that to go and to set up everything in IIS instead of having to script out everything within PowerShell. And then Icame across another post saying they're actually going to be releasing a command-line version of the Web Platform Installer, and that's where Ibasically went-well, this is the most optimal way to install something in Azure.
Franklin:Right.
Fowler:Because everything is relatively handled. You can do a lot with the Web Platform Installer, I should just be using this.
Campbell:Yeah, because when you think I'm going to use a Web Platform Installer, [your] first thought is that that's a wizard, that's a lot of dialogs to makethat work. But I did not know that there was a command-line version of Web Platform Installer, so that's pretty cool.
Fowler:Yeah, they basically released it specifically for Azure. But there's an x86 version, and then there's an any-CPU version, and you want to use theany-CPU version when you're trying to deploy something within Azure just because most or all of the Azure instances are running 64-bit software.
Campbell:Right.
Fowler:And the 64-bit operating system. So that's the tool you want to use. But if you have anything that you want to set up that's using the WebPI, you canbasically go ahead and just install everything through that.
Campbell:That's very neat. I did not realize it's there because there are all kinds of things in the Web Platform Installer. This is all for the web role inAzure?
Fowler:Yeah. The only difference between the web role and the worker role is basically, the web role already has IIS and everything set up.
Campbell: OK.
Fowler:But you could use-if you're encoding video and you wanted to install a video encoder on a worker role, you could still set that up through Web PlatformInstaller. You just wouldn't be using components in IIS, but you could still use that tool to install [Microsoft] Expression Encoder.
Franklin:Right.
Fowler:Right, within a worker role.
Campbell:Right. It's interesting that that's the only difference between the two. They're just preconfigured that way. So you're using a web role and then usingWebPI command line to push against that, the copy of IIS, and set up all the PHP stuff, like there's a lot of different pieces that have to beinstalled.
Fowler:Yup. There's the PHP handler mapping that you need to set up for fast CGI, so it needs to know exactly that it goes to the fast CGI module, which italso sets up, and then basically it also installs the PHP executables within program files. So there are a lot of different pieces that, if I did gothat PowerShell route, I have to try and manually go through a script through the entire process.
Campbell:So where does the Windows Azure SDK fit into the equation?
Fowler:There is a PHP version of the Windows Azure SDK-so if you wanted to use table storage, blob storage, queues, or any other functionality that Azure canprovide, there is a port for the SDK in PHP. So I went and installed that as well, and it's just basically taking the DLL and pushing it into theextensions folder within the PHP folder on your box. And then, basically, you can use that. It's going to load up that module in the PHP handler, andyou can use that to execute functionality against storage, the storage provider.
Campbell:So this is really not a hack. This is actually a supported configuration by Windows Azure.
Fowler:Yeah, they actually have SDKs for a lot of open source languages. There's a Ruby SDK, there's a Java SDK. And that is why I'm kind of trying to pushthis along-it's the fact that Microsoft is really supporting open source here on Windows Azure, and no one is pushing it out there and saying hey,look, you can do this on Azure, you might as well use the system that we've pulled up. We're going to be constantly moving forward in the open sourceworld, so I'm just trying to call it out as much as I possibly can to get people on the platform because it's a great platform.
There's much more! You can find the full interview at dotnetrocks.com/default.aspx?showNum=651.
Richard Campbelland Carl Franklin (both Microsoft Regional Directors) are the voices and brains behind .NET Rocks! (www.dotnetrocks.com). Theyinterview experts to bring you insights into .NET technology and the state of software development. They're more than dry technical interviewers-theyhave fun!
About the Author
You May Also Like