how to change path of php ini windows

I've downloaded php, addeded it to my path and im trying to enabled openssl

php --ini tells me that configuration file is c:\windows which there was nothing there, I dont want to copy php into c/windows.

How do I change this to point at my php folder?


Solution 1:

You do not need to put anthing to do with PHP anywhere near the c:\windows folder.

If you do it will only serve to mess you up when you upgrade PHP to a new version.

If you CD to the folder that PHP is installed in and do a php --ini it will read the php.ini file from the folder that you are in.

D:\wamp\bin\php\php5.5.12>php --ini
Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File:         D:\wamp\bin\php\php5.5.12\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

I think its also a bad idea to put the PHP install folder in the windows PATH as well.

All you need is a little batch file that will setup your PATH for the duration of the command window you are using, and put that in one of the folders that is already in the windows PATH.

So assuming you installed PHP into C:\php this is the batch file

phppath.cmd

PATH=%PATH%;C:\php
php --ini
php -v

And you then just run this batch file any time you open a command windows and want to run some PHP code and your environment gets configured. You can also add other things to this batch file when you need other things added to your environment like Composer etc.

Solution 2:

According to documentation:

The configuration file (php.ini) is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. For the CGI and CLI versions, it happens on every invocation.

php.ini is searched for 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 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).
  • 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.

You should try either the PHPRC environment variable or registry key [HKEY_LOCAL_MACHINE\SOFTWARE\PHP].