What is the difference between php.ini and .user.ini in each folder?

Viewed 397

I am trying to understand the difference between the php.ini and .user.ini in each folder. I read this document https://www.php.net/manual/en/configuration.file.per-user.php but still not very clear about that.

If I am understanding properly, php.ini under a folder, such as /home/alan/public_html/ will affect all subfolders such as /home/alan/public_html/test/. But .user.ini under /home/alan/public_html/ will only affect this folder, not its subfolders, is that correct?

Update

I am using cPanel MultiPHP Editor and check this doc https://docs.cpanel.net/cpanel/software/multiphp-ini-editor-for-cpanel/. It said "The Basic Mode section of this interface loads directive values from the php.ini file for your selected domain or home directory. Make your changes to the desired directives and click Apply. The system saves changes to the php.ini file, the user.ini file, and your .htaccess file.

So it seems both php.ini and user.ini can be folder specific.

1 Answers

There is only one php.ini file that affects all PHP scripts.

You can have custom .ini files with a default filename .user.ini but changeable using the user_ini.filename option in your main php.ini file that can have overrides to the main php.ini. PHP will not read more than one php.ini file. What can be overridden are directives that are flagged as PHP_INI_PERDIR and PHP_INI_USER in this page.

Any .user.ini file will affect the folder it is in and all subfolders. This only happens when using php-fpm the the PHP FastCGI module i.e. if you're not using php-fpm then any .user.ini files have no effect.

If you plan to use .user.ini configuration also read https://www.php.net/manual/en/configuration.file.per-user.php#124175 on how to protect it from being accessed

Related