PHP .user.ini Doesn't Work

Author:
phil
Created:
Wednesday, April 03rd, 2013
Last Updated:
Wednesday, April 03rd, 2013

Disclaimer: Accessing the information on this page means you agree to the Sites Terms of Service


In the olden PHP days, if you wanted to set a php.ini file per user directory, you would configure all sorts of PHP and Apache magic smoke stuff and PHP would recognize the php.ini file in a users folder. From my understanding, this is still the case when using mod_php...

Starting around PHP 5.3, if you decided to run fcgid instead, you are now allowed to create a file called .user.ini and add your php settings inside of it. Now, if you're like me, you absolutely hate the PHP documentation because lets face it... The PHP documentation authors are apparently from another planet. Unless you speak some sort of alien lingo, there's no way to get anything of use from the PHP documentation... That's why you did some more searching in hopes that someone else figured out what's going on.

While I can't give all sorts of fancy "know-how" details about the .user.ini file, the one thing the documentation points out that I had no clue about for the hour and a half of trying to get it to work, are the two PHP "modes" PHP_INI_PERDIR and PHP_INI_USER. At first, I thought you added these to the master php.ini file and enabled it or something. But that's not what you do... What these mean is that any PHP directive that use these modes, can be set in the .user.ini file. If the directive doesn't process in that mode, you won't be able to change it.

So, after an hour and a half of trying to figure out how to get .user.ini to work, I ran across an article that pointed me to the following PHP documentation page: http://www.php.net/manual/en/ini.list.php

Once I hit that page, it all became clear to me. I can ONLY set the stuff where the Changeable column states PHP_INI_PERDIR or PHP_INI_USER or PHP_INI_ALL

For example, I wanted to disable the APC cache (apc.enable = 0) for a particular sandbox site because it was interfering with updating the code. I jacked around for who knows how long, trying to figure out how to disable APC. But, when I ran across the ini.list page, I noticed up there at the very top that apc.enabled can only be set at PHP_INI_SYSTEM which is the master php.ini file.

It also states PHP_INI_SYSTEM in APC 2. PHP_INI_ALL in APC <= 3.0.12. which tells me that I "should" be able to disable it through the .user.ini file, but for some reason, it isn't and at the moment, I'm running APC 3.1.13 so I'm clueless on that one...

Regardless, if you're trying to figure out how to get .user.ini to work with a particular directive, check the ini.list documentation and see if the directive you're trying to set, can infact be set at the user level, per directory level or all level. It might save you some headache.

I'll also note that I tested the .user.ini file with and without the [PHP] heading and it seemed to work fine either way.

You might have also noticed the two directives in the main documentation: user_ini.filename and user_ini.cache_ttl which if you look at the changeable mode in the ini.list page, you'll notice these can only be set in the master php.ini file through PHP_INI_SYSTEM.

Post Comment