How to use CakePHP on Windows Azure Web Sites

On June 13, 2013 the Windows Azure Web Sites team announced support for CakePHP in the Windows Azure App Gallery. Check out the post on Installing CakePHP from the Windows Azure Web Site Gallery

One day Last week, I set out to get a simple CakePHP site up and running on Windows Azure Web Sites.

CakePHP is an open source MVC framework for building PHP applications.

CakePHP is a framework, which means ideally, there should not be anything specific to get it working on any platform. As I suspected this is exactly the case, you can simply:

  1. Download CakePHP 2.2.1
  2. Unzip the Package
  3. Deploy to Windows Azure Web Sites
    1. Upload files to Windows Azure Web Sites with FTP or;
    2. Deploy Windows Azure Web Sites applications with Git
  4. Build your Application
    1. I used the CakePHP Blog Tutorial to test the functionality

CakePHP on IIS (aka Windows Azure Web Sites)

One thing to note about hosting CakePHP applications on Windows Azure Web Sites is that your site will be running in IIS. As such you do need to add a web.config to your deployment to get the friendly urls to work as IIS does not know how to decipher .htaccess files [Import Apache mod_rewrite rules using IIS Url Rewrite tool].

Here is a sample web.config file [found on the CakePHP site] for running CakePHP in Windows Azure Web Sites.

Happy Clouding!

Accessing App Settings Configured in Microsoft Azure Web Sites using PHP and Node.js

When developing for Microsoft Azure Web Sites, you will undoubtedly come across the CONFIGURE tab in the Azure Management Portal. Within the CONFIGURE tab you will find a section labeled ‘app settings’, in ASP.NET Development, app settings are name-value pairs typically found in the web.config file.

Setting the variables is very simple, follow these steps:

  1. Login to the Azure Management Portal.
  2. Click on Web Sites in the left navigation.
  3. Select a Web Site from the list.
  4. Click on CONFIGURE.
  5. Scroll down to app settings.
  6. Provide a key and value.

image

How do I access App Settings using PHP or Node.js

App Settings set in the Management Portal take priority over the <appsettings> which are set in the web.config file, interestingly enough, the settings are not overwritten. This will most likely pose the question, how do I access these settings from other open source languages that don’t have the notion of a web.config file?

These settings from the App Settings section are conveniently place in the OS Environment Variables which makes them simple to read from other programming languages. I know what you’re thinking, aren’t there a number of really important pieces of information in Environment Variables that could get overwritten?

Technically, Yes.

However, the Microsoft Azure Web Sites team has thought of that and exposes error messages when attempting to overwrite important System Variables.

image

Samples

Accessing Environment Variables using PHP

There are two ways to access Environment Variables in PHP, however only one of them is enabled within Microsoft Azure Web Sites.

  • $_ENV – Not Supported on Microsoft Azure Web Sites.
  • getenv() – Supported on Microsoft Azure Web Sites

Accessing Environment Variables using Node.js

In node.js the process object contains a property env which exposes the Environment Variables. Calling process.env and providing the key of the Environment Variable you wish to access using dot notation will retrieve the value.

Supporting Node.js Files

Trying Out the Samples

If you wish to download the code from the Gists and run these samples it is possible. Uploading both to the same Microsoft Azure Web Site will only allow you to access one as the default document. The Node.js app is going to take priority. In order to view the PHP sample, simply access the index.html page directly [http://you-sub-domain.azurewebsites.net/index.php].

If you currently don’t have a Microsoft Azure Subscription, Try Microsoft Azure Today.

Happy Clouding!

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 WindowsAzure.com.

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).

Back and Better than Ever. Oooo Shiny!

Cory Fowler | Microsoft | Windows Azure Technical Evangelist It’s been a little while since I’ve blogged so before I get back into the swing of things, I want to take a step back to reflect a few recent changes.

In April 2012, I joined Microsoft Corporation as a Windows Azure Technical Evangelist.

As a part of joining Microsoft, I had to relinquish my title of Windows Azure MVP. Even though it was difficult to swallow, I keep in mind that I was at the forefront of Windows Azure, an inaugural member of the Windows Azure MVP program, as well as Canada’s first [and for the longest time only] Windows Azure MVP. These thoughts are what continues to drive me to provide some great content around Windows Azure.

My role at Microsoft is focused around bringing new communities to Windows Azure focusing primarily on Open Source Technologies.

I’ve been meaning to migrate my blog to WordPress for quite some time, it just seemed much more fitting now that I can not only use WordPress as my primary blog engine, but I am able to host it on Windows Azure using one of the new features introduced in the spring preview rightfully named Windows Azure Web Sites.

Thanks for visiting my new blog and look forward to seeing some great content continue to flow on the subject of Windows Azure.

Happy Clouding!