6

I'm trying to learn Symfony that "requires" using php in the command line / terminal for some tasks.

I like to store my php.ini in the /apache2/conf directory, to have all the server configs at one place (and not having to deal with Windows' UAC everytime I change something). In Apache, it's no problem to set the default php.ini location via

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 there's none 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 bypass this by using the php -c C:\apache2\conf ... everytime I use it but I'd prefer a more easy and permanent solution.

Is this possible? Thanks in advance!

4
  • You can override php.ini values via .htaccess and httpd.conf. Rather than maintain two seperate .ini files, you could have one global one, and then a few overrides in your Apache .conf files. Commented Feb 18, 2011 at 20:35
  • @profitphp I agree with the sentiment of your comment but don't see how using Linux would change anything in this case. Commented Feb 18, 2011 at 20:42
  • Marc, I don't want to have two separate .ini files, that is exactly the point. But my problem was with CLI, so neither .htaccess or httpd.conf would help. Fixed now, thanks anyway! Commented Feb 18, 2011 at 21:05
  • profitphp, I tried it many times, with quite a few distributions and it never got close to my heart. Maybe next time :P Commented Feb 18, 2011 at 21:06

2 Answers 2

8

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

php.ini is searched in these locations (in order):

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

  • The 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 examined in order: [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 these keys, then 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).

  • Current working directory (except CLI)

  • The web server's directory (for SAPI modules), or directory of PHP (otherwise in Windows)

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

How silly of me, I couldn't find it with Google and didn't think of checking the manual... I've used the environment variable and works perfect, thanks!
0

Try adding this registry key

HKEY_LOCAL_MACHINE\SOFTWARE\PHP\5\IniFilePath -> (your path)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.