Setting up a custom path to php.ini (not in Apache)

I am trying to learn Symfony, which "requires" the use of php on the command line / terminal for some tasks.

I like to store my php.ini in the /apache2/conf directory in order to have all the server configurations in one place (and I do not need to deal with Windows UAC every time I change something). Apache no problem setting php.ini default location with

 PHPIniDir "C:/apache2/conf" 

However, when running php from the terminal - not through the apache server - it looks for the file in the C: \ Windows directory by default, although it is not there:

 C:\>php -i ... Configuration File (php.ini) Path => C:\Windows Loaded Configuration File => (none) Scan this dir for additional .ini files => (none) Additional .ini files parsed => (none) ... 

Of course, I can get around this using php -c C:\apache2\conf ... every time I use it, but I would prefer a lighter and more permanent solution.

Is it possible? Thanks in advance!

+5
source share
2 answers

http://www.php.net/manual/en/configuration.file.php

php.ini searches in these places (in order):

  • The specific location of the SAPI module (directive PHPIniDir in the Apache 2 command line option, -c in CGI and CLI, php_ini parameter in NSAPI, PHP_INI_PATH environment variable in THTTPD)

  • PHPRC environment variable. Before PHP 5.2.0, this was checked after the registry key mentioned below.

  • As of PHP 5.2.0, the location of the php.ini file can be set for different versions of PHP. The following registry keys are considered in the following order: [HKEY_LOCAL_MACHINE \ SOFTWARE \ PHP \ xyz], [HKEY_LOCAL_MACHINE \ SOFTWARE \ PHP \ xy] and [HKEY_LOCAL_MACHINE \ SOFTWARE \ PHP \ x], where x, y and z mean major PHP, minor and release versions. If these keys have a value for IniFilePath, then the first one will be used as the location of php.ini (for Windows only).

  • [HKEY_LOCAL_MACHINE \ SOFTWARE \ PHP], value IniFilePath (Windows only).

  • Current working directory (except CLI)

  • Web server directory (for SAPI modules) or PHP directory (otherwise on Windows)

  • Windows directory (C: \ windows or C: \ winnt) (for Windows) or the -with-config-file-path option to compile

In addition to PHP 5.3, you can use .ini files for each directory. See http://php.net/manual/en/configuration.file.per-user.php

+7
source

Try adding this registry key.

HKEY_LOCAL_MACHINE \ SOFTWARE \ PHP \ 5 \ IniFilePath → (your path)

0
source

All Articles