1

How do you load a .user.ini PHP configuration file when using the built in web server?

My setup is like this:

site
│   include.php
│
├───bin
│       router.php
│       server.bat
│
└───public
        .user.ini
        index.php

The document root is public, and bin\router.php routes to public\index.php if the file does not exist.

I did a phpinfo(), to verify that the .user.ini was not being loaded. The setting I am trying to change is error_log.

hakre
  • 193,403
  • 52
  • 435
  • 836
Petah
  • 45,477
  • 28
  • 157
  • 213

2 Answers2

2

Petah, I've just twigged what the issue is from your comment. The built-in webserver was only introduced in 5.4

This web server is designed for developmental purposes only, and should not be used in production.

It acts as a webserver listening on the specified socket. The .user.ini states that:

These files are processed only by the CGI/FastCGI SAPI. This functionality obsoletes the PECL htscanner extension. If you are using Apache, use .htaccess files for the same effect.

In other words you can't use .user.ini files with the built-in webserver or with Apache/mod_php, etc. You have to use a custom php.ini. The safest way to do this is to clone the default php.ini (or php_value/flag directives with Apache/mod_php) and then add the lines you want for development. Of course you could always just add an ini_set command in you script(s) startup as well.

TerryE
  • 10,724
  • 5
  • 26
  • 48
  • 1
    I understand your points. But its a shame, as I can't use the system php.ini file (with the OS specific stuff), and then supplement a few options per site. – Petah Jun 15 '12 at 20:14
1

While not an exact answer to my question, I found a solution to my problem.

In the server.bat file I was running the php server using

php -S 0.0.0.0:3000 -t public bin/router.php

By changing it to:

php -c public/.user.ini -S 0.0.0.0:3000 -t public bin/router.php

Achieved the same effect.

Petah
  • 45,477
  • 28
  • 157
  • 213
  • 1
    Petah, I guess that this is a Windows-specific Q&A. All the -c option does is to force the path of the **php.ini**. This is *not* the same as the 5.3+ `.user.ini` which supplements the main **php.ini**. – TerryE Jun 14 '12 at 09:53
  • Not really Windows specific, I'm just on Windows this second. But I do agree the solution is not perfect so I'm still looking for an answer. – Petah Jun 15 '12 at 01:42
  • One way to do it would be to use `<(cat file1.ini file2.ini)` to combine settings. But it is not very easily to implement to match how PHP looks for ini files in CLI method. You have to take into account `PHPRC` variable as well. – CMCDragonkai Mar 08 '17 at 00:51