Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly use `.user.ini`-file in PHP?

Tags:

php

settings

ini

In my working directory I have two files: index.php and .user.ini:

.user.ini:

display_errors=on

; http://be2.php.net/manual/en/filter.configuration.php#ini.filter.default
;filter.default = "full_special_chars"

index.php:

<?php
//ini_set("display_errors", "on");

// Use `.user.ini` file:
// http://php.net/manual/en/configuration.file.per-user.php
echo "Setting for 'user_ini.filename': " . ini_get("user_ini.filename");
echo "\n\n";


// It takes up to five minutes, until `.user.ini` is re-read:
echo "Setting for 'user_ini.cache_ttl': " . ini_get("user_ini.cache_ttl");
echo "\n\n";

// http://php.net/manual/en/function.ini-get.php
echo "Setting for 'display_errors': " . ini_get("display_errors");
echo "\n\n";
echo "Setting for 'filter.default': " . ini_get("filter.default");
echo "\n\n";

// php -S localhost:8000
// http://localhost:8000/

Using the above .user.ini-file (in my working directory) I expect the "Setting for 'display_errors': " having a value of on or 1, but it's empty.

How to correctly change settings using the .user.ini-file?

running php --ini results in

Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:         /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed:      /etc/php5/cli/conf.d/05-opcache.ini,
/etc/php5/cli/conf.d/10-pdo.ini,
/etc/php5/cli/conf.d/20-json.ini,
/etc/php5/cli/conf.d/20-readline.ini

which does not contain my .user.ini-file.

Explicitly adding the .user.ini-file works:

php --php-ini .user.ini index.php

but I'd like it to be automatically read when running the script from a given folder.

like image 915
Edward Avatar asked Aug 24 '15 09:08

Edward


People also ask

What is the use of ini file in PHP?

The php. 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.

Where do I add user ini?

A . user. ini file needs to be in the root of the application or website with the settings configured you wish to change.


1 Answers

instead of use .htaccess for php config , u can create .user.ini file and put setting (without any indent or space) . for example my .user.ini config is:

max_execution_time =600
upload_max_filesize=200M
post_max_size=200M
memory_limit=256M 
like image 132
fatemeh sadeghi Avatar answered Oct 08 '22 06:10

fatemeh sadeghi