Configuring PHP in Windows Azure Websites with .user.ini Files

I wrote a post a few weeks ago (Windows Azure Websites: A PHP Perspective) in which I suggested using the ini_set function to change PHP configuration settings in Windows Azure Websites. While that approach works, I briefly want to point out in this post that you can use a .user.ini file to configure PHP in Windows Azure Websites. If you are familiar with using .user.ini files, then you can just start using them. If you aren’t familiar with .user.ini files, the approach is detailed here: .user.ini files. Basically, you create a file called .user.ini that contains PHP configuration settings and put it in your root directory (or a subdirectory if you want the settings to only apply there). For example, let’s say I wanted to turn display_errors on and change the upload_max_filesize setting to 10 megabytes. Then the contents of my .user.ini file would simply be…

 display_errors = On
 upload_max_filesize = 10M

One “git push azure master”, and my custom PHP configuration settings are in effect for my site…almost. The one gotcha I ran into here that the frequency with which PHP reads .user.ini files is governed by the user_ini.cache_ttl setting, which is 300 seconds (5 minutes) by default. And, since this is a master setting in the php.ini file, you can’t change it. If, however, you want to see your changes in effect right away, you can simply stop and re-start your website.

One other thing worth noting here is that you cannot change PHP configuration settings that have mode PHP_INI_SYSTEM. To see a list of settings and their modes, see List of php.ini directives.

That’s it!

Thanks.

-Brian