2 PHP.Ini Files

2 php.ini files

Depends on where you are running PHP from. If you run it from command line, it uses the cli/php.ini and apache2/php.ini when run through apache.

You are executing phpinfo() through the browser, hence you get /etc/php5/apache2/php.ini as the answer. Running php -r "phpinfo();" | grep "Loaded Configuration" from the terminal should output the CLI ini. Same function, context changes.

The advantage of this system is obviously to allow different configurations depending on the context. For a simplified example, you might want to have safe_mode on in apache but it's unnecessary in CLI mode.

Your .ini paths are actually quite unusual. Normally, the default .ini is just php.ini and CLI .ini is called php-cli.ini and they reside in the same folder.

I'm no expert on the subject but this should be the basic idea. If anyone has any corrections, I'd be happy to hear them.

Who reads the 'php.ini' file and how many php.ini files can possibly be exist there? What's the role of every such 'php.ini' file?

  1. The PHP compiler/parser.
  2. Because PHP does not persist for command line invocations, so it is read at run-time.
  3. Every time you call a PHP script, either CGI or CLI.
  4. More than one, typically 2. One for the web server and one for CLI/CGI.

WAMPserver, two php.ini files

The one from Apache folder is used for the web and the one from the PHP folder is used for the CLI.

If you want to update something on your php.ini related to a problem / an improvement on the web, you should update the one inside the Apache folder.

If you need some fine tuning on a task, which is launched using the CLI version of PHP, you should update the one in the PHP folder.

How do I include a php.ini file in another php.ini file?

I don't think you can "include" .ini files from the main php.ini file.

One possible solution, though, might be to use this option on the configure line, when compiling PHP:

--with-config-file-scan-dir=PATH
Set the path where to scan for configuration files

If this option is used at compile-time, PHP will look for every .ini file in this directory, in addition to the "normal" php.ini file.

I suppose this is what is used by Ubuntu, for instance, which uses a different .ini file for each downloaded extension, instead of modifying php.ini.

The path to the php.ini file is being defined with this option, on the configure line:

--with-config-file-path=PATH
Set the path in which to look for php.ini [PREFIX/lib]

Still, it probably means you'll have to re-compile PHP -- which is not that hard, btw -- the hardest part being to get the dependencies you need.

And, here is a post on the internals@ mailling-list that says the same thing as I do: config files and PHP_CONFIG_FILE_SCAN_DIR

Why are there many php.ini files in a system?

php.ini exists for the global web server process. It can also exist for each individual vhost.

It is searched for in the following order:

  • The PHPIniDir directive defined by the vhost
  • The PHPRC environment variable (as of PHP 5.2.0)
  • If on Windows and PHP 5.2.0 or greater, the following registry keys
    [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z], [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x], where x, y and z mean the PHP major, minor and release versions. If there is a value for IniFilePath in any of these keys, the first one found will be used as the location of the php.ini (Windows only).
  • [HKEY_LOCAL_MACHINE\SOFTWARE\PHP], value of IniFilePath (Windows only).
  • The current working directory
  • The web server's directory
  • If on Windows, the Windows directory (C:\Windows)

WAMPserver - why is the stack installed with 2 php.ini files?

One from the PHP folder is for Command Line interaction, the other is for Apache itself (Web browser).

I use the CLI for my IDE (netbeans).



Related Topics



Leave a reply



Submit