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:
- Login to the Azure Management Portal.
- Click on Web Sites in the left navigation.
- Select a Web Site from the list.
- Click on CONFIGURE.
- Scroll down to app settings.
- Provide a
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?
However, the Microsoft Azure Web Sites team has thought of that and exposes error messages when attempting to overwrite important System Variables.
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
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.