[ Solved -8 Answers] PHP – How to find the php.ini file used by the command line

How to find the php.ini file used by the command line - You will see in PHP folder there is an extension folder with all dll's

  • we need to enable pdo_mysql in my EasyPhp environment, so we went to php.ini file and uncommented the following line:
php code

Unfortunately we still have the same problem. By using the CLI so  suppose we need to locate the php.ini file used by the CLI. How can we find it?

  • You can get a full phpinfo() using :
php code
 php -i 
  • And, in there, there is the php.ini file used :
php code
$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
  • On Windows use find instead:
php code
php -i|find/i"configuration file"

php code
  php –ini
  • will give you all the details on the uses path and possible ini file(s)

  • You can use get_cfg_var(‘cfg_file_path’) for that:
  • To check whether the system is using a configuration file, try retrieving the value of the cfg_file_path configuration setting. If this is available, a configuration file is being used.
  • Unlike phpinfo() it will tell if it didn’t find/use a php.ini at all.
php code
var_dump( get_cfg_var('cfg_file_path') );
  • And you can simply set the location of the php.ini.
  • You’re using the command line version, so using the -c parameter you can specifiy the location, e.g.
php code
php -c /home/me/php.ini -f /home/me/test.php

  • If you want all the configuration files loaded, this is will tell you:
php code
php -i | grep "\.ini“
  • Some systems load things from more than one ini file. On my ubuntu system, it looks like this:
php code
$  php -i | grep "\.ini"
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
Scan this dir for additional .ini files => /etc/php5/cli/conf.d
additional .ini files parsed => /etc/php5/cli/conf.d/apc.ini,

  • If you need to pass it to another app, you can do something like:
php code
php --ini | grep Loaded | cut -d" " -f12
  • returns the path only. php -c $(php –ini | grep Loaded | cut -d” ” -f12) will pass in the config file (useful for fpm)

  • In your php.ini file set your extension directory, e.g:
php code
extension_dir = "C:/php/ext/“
  • You will see in you PHP folder there is an extension folder with all the dll’s and extensions.

  • From what we remember when we used to use EasyPHP, the php.ini file is either in C:\Windows\ or C:\Windows\System32

  • There is no php.ini used by the command line. You have to copy the file from …EasyPHP-<<version>>\apache\php.ini to …EasyPHP-<<version>>\php\php.ini than edit the one in php directory

About the author

Wikitechy Editor

Wikitechy Founder, Author, International Speaker, and Job Consultant. My role as the CEO of Wikitechy, I help businesses build their next generation digital platforms and help with their product innovation and growth strategy. I'm a frequent speaker at tech conferences and events.


Click here to post a comment