Ficheros .user.ini

A partir de PHP 5.3.0 se incluye soporte para ficheros de configuración INI a nivel de directorios. Estos ficheros solo los procesa la SAPI CGI/FastCGI. Esta funcionalidad deja obsoleta la extensión PECL htscanner. Si está usando Apache, use los ficheros .htaccess para lograr el mismo efecto.

Además del fichero php.ini principal, PHP explora cada directorio en busca de ficheros INI, empezando por el directorio del fichero PHP solicitado, y continuando hasta el directorio raíz de documentos (tal y como esté establecido en $_SERVER['DOCUMENT_ROOT']). En el caso de que el fichero PHP se encuentre fuera del directorio raíz de documentos, sólo se explorará su directorio.

En los ficheros INI estilo .user.ini sólo se reconocerán las cofiguraciones INI que tengan los modos PHP_INI_PERDIR y PHP_INI_USER.

Las dos nuevas directivas INI, user_ini.filename y user_ini.cache_ttl controlan el uso de los ficheros INI de usuarios.

user_ini.filename establece el nombre del fichero que PHP buscará en cada directorio; si se establece un string vacío, PHP no realizará ninguna búsqueda. El nombre por omisión es .user.ini.

user_ini.cache_ttl controla con qué frecuencia se releen los ficheros INI de usuario. El valor por omisión es 300 segundos (5 minutos).

add a note add a note

User Contributed Notes 8 notes

up
21
Anteaus at thenox dot com
4 years ago
"If you are using Apache, use .htaccess files for the same effect."

To clarify, this applies only to Apache module mode. If you put php directives in .htaccess on an Apache CGI/FastCGI server, this will bomb the server out with a 500 error. Thus, you unfortunately cannot create a config which caters for both types of hosting, at least not in any straightforward way.
up
21
philsward at gmail dot com
5 years ago
If you have no idea what "PHP_INI_PERDIR" or "PHP_INI_USER" are or how they relate to setting a .user.ini file, take a look at the ini.list page: http://www.php.net/manual/en/ini.list.php

Basically, anything in the "Changeable" column labeled as PHP_INI_SYSTEM can't be set in the .user.ini file (so quit trying).  It can ONLY be set at the main php.ini level.
up
12
interfaSys
7 years ago
This article should be made clearer.
".htaccess-style INI files" meant to me that the ini settings had to follow the syntax used in .htaccess, but this is not the case!

You have to use
register_globals=on
and not
php_flag register_globals on

Also, the changes can take a while to propagate to all processes if you have a long process time out.
Restarting php-fpm can give you an answer quicker :)
up
1
StanE
10 months ago
Just for clarification: The file name is indeed ".user.ini" (with a trailing dot), not "user.ini". This is not a misspelling.

But "php.ini" is without a trailing dot.
up
0
Anonymous
2 months ago
> Thus, you unfortunately cannot create a config which caters for both types of hosting, at least not in any straightforward way.

That's actually not true, as you can easily wrap all PHP things in conditional block in .htaccess using <IfModule>, i.e.

    <IfModule mod_php7.c>
       php_value ....
    </IfModule>
up
-1
info at vincentraal.nl
19 days ago
Be aware that PECL htscanner doesn't work (yet) on PHP7.0.

'pecl install htscanner' throws an "zend_hash_update’ undeclared'" error.
up
-6
amillionlobsters at gmail dot com
9 months ago
Note that, while the documentation's claim that "only settings with the modes PHP_INI_PERDIR and PHP_INI_USER will be recognised" is technically correct, it's ambiguous: settings with the modes PHP_INI_ALL will be recognised, because PHP_INI_ALL = PHP_INI_PERDIR | PHP_INI_USER | PHP_INI_SYSTEM.
up
-123
Anonymous
2 years ago
One of the most used is to limit the uploading size and memory limit:

upload_max_filesize = 1000M
post_max_size=1005M
max_execution_time=120
To Top