Does the .user.ini file work for subdirectories?

前端 未结 2 1463
鱼传尺愫
鱼传尺愫 2021-01-11 21:41

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

2条回答
  •  萌比男神i
    2021-01-11 22:24

    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.

    
        
                SetHandler "proxy:unix:/var/lib/php/php-fpm.sockets/site.sock|fcgi://localhost/"
        
        DirectoryIndex index.php index.html index.htm
    
    

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

    
        
                SetHandler "proxy:unix:/var/lib/php/php-fpm.sockets/site.sock|fcgi://localhost"
        
        DirectoryIndex index.php index.html index.htm
    
    

    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/ ).

提交回复
热议问题