Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the .user.ini file work for subdirectories?

Tags:

php

php-5.3

Does the .user.ini file that controls folder specific PHP settings also descend into the subfolders?

I was reading a few websites and they suggest that it does (albeit there is not alot of information about it), however I've found that if I run a script from a subfolder, it doesn't use the settings from the .user.ini file.

Am I missing something or is it only meant to be for the same folder that the script is executing from? If so, is there a way to make php scripts look for the .user.ini file from the parent folder etc?

like image 498
Lock Avatar asked Dec 01 '14 10:12

Lock


People also ask

What does user INI file do?

The . user. ini file is where you declare changes to your PHP settings. You can use the default settings for the server, change specific settings by editing the existing .

Where is user INI located?

user. ini file is the default configuration file for running applications that require PHP. It is used to control variables such as upload sizes, file timeouts, and resource limits. This file is located on your server in the /public_html folder.


1 Answers

Yes, it should work. However, I had the same issue with .user.ini files not setting php_value's recursively. According to official (and short) documentation on php.net they should work recursively (as .htaccess did):

PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). In case the PHP file is outside the document root, only its directory is scanned.

What I have found out is that Apache configuration had one trailing slash too much which caused .user.ini files not to work recursively.

Take a look at your phpinfo(), specifically SCRIPT_FILENAME variable. Notice two slashes - where should be just one:

$_SERVER['SCRIPT_FILENAME'] = //home/site/public_html/phpnfo.php

The reason for this was coming from apache config, which contained one trailing slash too much.

<IfModule !mod_php5.c>
    <FilesMatch \.php$>
            SetHandler "proxy:unix:/var/lib/php/php-fpm.sockets/site.sock|fcgi://localhost/"
    </FilesMatch>
    DirectoryIndex index.php index.html index.htm
</IfModule>

Apache config doesn't include trailing slashes for directories so instead of fcgi://localhost/ this should be written as fcgi://localhost like this:

<IfModule !mod_php5.c>
    <FilesMatch \.php$>
            SetHandler "proxy:unix:/var/lib/php/php-fpm.sockets/site.sock|fcgi://localhost"
    </FilesMatch>
    DirectoryIndex index.php index.html index.htm
</IfModule>

After change, restart Apache/php-fpm and you are set.

Update: As it turns out, trailing slash errors in Apache config are still common thing and can lead to different errors and bad php practices (eg set in DocumentRoot /var/www/web/ ).

like image 140
seven Avatar answered Oct 31 '22 08:10

seven