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

When developing for Windows Azure Web Sites, you will undoubtedly come across the CONFIGURE tab in the Windows 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 Windows 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 Windows 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 Windows Azure Web Sites.

  • $_ENV – Not Supported on Windows Azure Web Sites.
  • getenv() – Supported on Windows 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 retreive 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 Windows 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 Windows Azure Subscription, Try Windows Azure Today [Free for 90-days].

Happy Clouding!

3 Responses

Leave a Reply