Getting Started with PHP on Windows Azure Web Sites

Windows Azure | Flexible. Open. Rock Solid.

Windows Azure Web Sites (WAWS) is a highly scalable cloud environment build for speed. Windows Azure Web Sites brings down the barriers of Cloud Deployment allowing you do deploy what you want (Support for ASP.NET, PHP & Node.js),  how you want (FTP, Git, TFS, WebDeploy).

In this post I would like to highlight some simple optimizations for  running a PHP Web Site within the Windows Azure Web Sites environment.

Strap on your Tool Belt…

There’s nothing a developer likes more than some a few tools to make the job a little easier. Windows Azure has simplified the process of getting the right tools for the job, to take this one step further, we provide installers for our tools for use on Linux, Mac and/or Windows.

Develop using Windows Azure Services

Visit the PHP Developer Center to install the PHP SDK for Windows Azure.

Manage your Windows Azure Services

You can manage your Windows Azure services all from the comfort of your favorite Command-Line. Visit the Manage downloads page to Get the tools you need. Fast.

In addition to providing Command-Line tools, Windows Azure services can also be managed directly from the Windows Azure Management Portal. The new Windows Azure Management Portal has been completely redesigned in HTML5 which enables it to be used in a variety of devices including Windows Phone and iPad. For Guides on how to navigate the Management Portal specifically related to WAWS, visit the Web Sites page of the Manage Services section on

Now for Something You’ll Really Enjoy…

In a world that demands instant gratification, performance is paramount, your Web Site needs to be able to deliver in a time of need. Even thought Windows Azure Web Sites has no issues being performing it’s still crucial that we think about optimizing for the best possible result. Luckily the team which built Windows Azure Web Sites has already done an amazing job delivering an environment which follows the Best Practices for running PHP on IIS.

Learning more about the Windows Azure Web Sites Environment

To better understand what is enabled by default in the PHP runtime on Windows Azure Web Sites, create a file called info.php which contains the following:

All of the Server Configuration Information you will need to understand what is capable in Windows Azure Web Sites in the context of PHP.

Installed PHP Modules

php_mysql.dll MySQL Driver for PHP
php_mysqli.dll Improved MySQL Driver for PHP
php_mbstring.dll Multibyte String [Encoding]
php_gd2.dll Image Processing and Creation Library
php_gettext.dll Native Language Support (Globalization & Localization)
php_curl.dll Protocol Support
php_exif.dll Image Metadata
php_xmlrpc.dll Remote Procedure Call
php_openssl.dll SSL Support
php_soap.dll SOAP Protocol
php_pdo_mysql.dll PHP Data Objects for MySQL
php_pdo_sqlite.dll PHP Data Objects for SQLite
php_imap.dll Mail Server Support [IMAP, POP3, NNTP]
php_tidy.dll HTML Document Manipulation
php_wincache.dll Windows Cache [Caches: Opcode, Files, File Paths, User Caching and Session Handling]
php_sqlsrv.dll MS SQL Server Driver for PHP (includes Windows Azure SQL Database Support)
php_pdo_sqlsrv.dll PHP Data Objects for MS SQL Server

Some of those settings don’t suit my needs, what do I do now?

In the event that some of the settings in the php.ini don’t suit your needs DON’T PANIC.

Windows Azure Web Sites allows .user.ini files, which allow you to set certain php.ini configuration values.

One caveat to the .user.ini file is that it will not allow you to install additional modules.

If your application requires additional modules than the ones listed above, you would probably want to look at Windows Azure’s Virtual Machine or Cloud Service offerings.

Debugging PHP in Windows Azure Web Sites

Every developer will inevitably at some point need to debug some code, it’s just a fact of life. If you look at the output from phpinfo() you’ll notice that errors are logged, but not displayed in the browser, which would significantly slow down developer productivity. Not to worry, here is a .user.ini file which will help you with debugging your PHP applications.

Note: Remove the [debug] from the file name.

Important Setting for Accepting Content in Windows Azure Web Sites

When moving my blog to WordPress on Windows Azure Web Sites, I needed to import my BlogML export from BlogEngine.Net unfortunately for me the file size was greater than the default 2MB. Luckily, Brian Swan wrote a post on Configuring PHP in Windows Azure Web Sites with .user.ini files which outlines how to increase the upload_max_filesize to 10MB (I’ve decided that 12MB  is my preferred upload_max_filesize).

Optimize web.config Settings for PHP

If you take a look at this post by Maarten Balliauw on Tweaking Windows Azure Web Sites you will see the two files which provide IIS the base configuration applicationhost.config and webroot.config. Maarten was investigating how to turn on additional HTTP Verbs in Windows Azure Web Sites for a Custom WebDav server. Seeing how more and more applications are using REST, it seems fitting that we enable the majority of HTTP Verbs by default so our application can leverage them.

In addition to adding HTTP Verbs, limiting the list of Default Documents that IIS must rotate through will help optimize page load times. With these two optimizations I have started a web.config starting point for PHP applications on Windows Azure Web Sites.

Note: This post reflects the original state of this file, which is hosted on GitHub and  may change overtime.

Migrating from Apache to Windows Azure Web Sites

If you are currently running an application Apache Web Server and would like to migrate your application Windows Azure Web Sites it’s completely possible, it’s even possible to translate your .htaccess file content to IIS web.config, or if you have a Windows machine, you can use the IIS Rewrite tool to Import mod_rewrite rules into IIS (then copied from the xml view into your web.config file).