Amokrane Chentir
Amokrane Chentir

Reputation: 30405

How can I find the php.ini file used by the command line?

I need to enable pdo_mysql in my EasyPHP environment, so I went to the php.ini file and uncommented the following line:

extension=php_pdo_mysql.dll

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

Upvotes: 497

Views: 597515

Answers (16)

rmoestl
rmoestl

Reputation: 3155

php -r 'var_dump(get_cfg_var("cfg_file_path"));'

Use PHP!

Upvotes: -1

lubosdz
lubosdz

Reputation: 4510

Since PHP uses different php.ini paths for HTTP(S) and CLI (console command line) mode, easiest way is to find out really loaded php.ini file is by saving phpinfo() output into local file:

php -i >> phpinfo-cli.txt

Open saved file & find row Loaded Configuration File. It will contain path to actually loaded php.ini file e.g.:

Loaded Configuration File => D:\wamp\bin\php\php7.4.1\php.ini

The above assumes that PHP is properly installed, e.g. on Windows included in PATH env. variable.

Upvotes: 4

DevWL
DevWL

Reputation: 18860

On Linux it is usually under /usr/bin/php

To find php.ini loaded in CLI on widows, run:

php.exe -i | grep "php.ini"

enter image description here

Ps. You can localize PHP installation folder with:

which php

enter image description here

or

whereis php

/c/laragon/bin/php/php-7.4.19-Win32-vc15-x64/php

Upvotes: 3

Ivan
Ivan

Reputation: 329

In a Docker container, "phpmyadmin/phpmyadmin". there isn't any php.ini file. But there are two files: php.ini-debug and php.ini-production.

To solve the problem, simply rename one of the files to php.ini and restart the Docker container.

Upvotes: 1

Han Van Pham
Han Van Pham

Reputation: 490

Try this if it could help you all:

find / -type f -name "php.ini" 

This will output all files named php.ini.

Find out which one you're using, usually apache2/php.ini

Upvotes: 4

kaiser
kaiser

Reputation: 22363

The easiest way nowadays is to use PHP configure:

php-config --ini-dir

Output:

/usr/local/etc/php/7.4/conf.d

There's more you can find there. The --help sub command (macOS local install):

php-config --help

Output:

Usage: /usr/local/bin/php-config [OPTION]
Options:
  --prefixUsage: /usr/local/bin/php-config [OPTION]
Options:
  --prefix            [/usr/local/Cellar/php/7.4.11]
  --includes          [-I/usr/local/Cellar/php/7.4.11/include/php - …ETC…]
  --ldflags           [ -L/usr/local/Cellar/krb5/1.18.2/lib -…ETC…]
  --libs              [ -ltidy -largon2 …ETC… ]
  --extension-dir     [/usr/local/Cellar/php/7.4.11/pecl/20190902]
  --include-dir       [/usr/local/Cellar/php/7.4.11/include/php]
  --man-dir           [/usr/local/Cellar/php/7.4.11/share/man]
  --php-binary        [/usr/local/Cellar/php/7.4.11/bin/php]
  --php-sapis         [ apache2handler cli fpm phpdbg cgi]
  --ini-path          [/usr/local/etc/php/7.4]
  --ini-dir           [/usr/local/etc/php/7.4/conf.d]
  --configure-options [--prefix=/usr/local/Cellar/php/7.4.11 --…ETC…]
  --version           [7.4.11]
  --vernum            [70411]

Upvotes: 6

antitoxic
antitoxic

Reputation: 3844

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 and then edit the one in the php directory.

Reference:

Upvotes: -6

Reece45
Reece45

Reputation: 2779

If you want all the configuration files loaded, this is will tell you:

php -i | grep "\.ini"

Some systems load things from more than one ini file. On my Ubuntu system, it looks like this:

php -i | grep "\.ini"

Output

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,
/etc/php5/cli/conf.d/curl.ini,
/etc/php5/cli/conf.d/gd.ini,
/etc/php5/cli/conf.d/mcrypt.ini,
/etc/php5/cli/conf.d/memcache.ini,
/etc/php5/cli/conf.d/mysql.ini,
/etc/php5/cli/conf.d/mysqli.ini,
/etc/php5/cli/conf.d/pdo.ini,
/etc/php5/cli/conf.d/pdo_mysql.ini

Upvotes: 8

VolkerK
VolkerK

Reputation: 96189

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.
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 specify the location for this particular run, e.g.

php -c /home/me/php.ini -f /home/me/test.php

Upvotes: 21

Sathish
Sathish

Reputation: 3557

Run php --ini in your terminal, and you'll get all details about ini files:

Configuration File (php.ini) Path: /etc
Loaded Configuration File:         /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed:      /etc/php.d/apc.ini,
/etc/php.d/bcmath.ini,
/etc/php.d/curl.ini,
/etc/php.d/dba.ini,
/etc/php.d/dom.ini,
/etc/php.d/fileinfo.ini,
/etc/php.d/gd.ini,
/etc/php.d/imap.ini,
/etc/php.d/json.ini,
/etc/php.d/mbstring.ini,
/etc/php.d/memcache.ini,
/etc/php.d/mysql.ini,
/etc/php.d/mysqli.ini,
/etc/php.d/pdo.ini,
/etc/php.d/pdo_mysql.ini,
/etc/php.d/pdo_sqlite.ini,
/etc/php.d/phar.ini,
/etc/php.d/posix.ini,
/etc/php.d/sqlite3.ini,
/etc/php.d/ssh2.ini,
/etc/php.d/sysvmsg.ini,
/etc/php.d/sysvsem.ini,
/etc/php.d/sysvshm.ini,
/etc/php.d/wddx.ini,
/etc/php.d/xmlreader.ini,
/etc/php.d/xmlwriter.ini,
/etc/php.d/xsl.ini,
/etc/php.d/zip.ini

For more, use helping command php --help. It'll display all the possible options.

Upvotes: 20

thomas-peter
thomas-peter

Reputation: 7944

Sometimes things aren't always as they seem when in comes to configuration files in general. So here I'm applying my usual methods for exploring what files are opened by a process.

I use a very powerful and useful command-line program called strace to show me what's really going on behind my back!

$ strace -o strace.log php --version
$ grep php.ini strace.log

Strace digs out kernel (system) calls that your program makes and dumps the output into the file specified by -o.

It's easy to use grep to search for occurrences of file php.ini in this log. It's pretty obvious looking at the following typical response to see what is going on.

open("/usr/bin/php.ini", O_RDONLY)      = -1 ENOENT (No such file or directory)
open("/etc/php.ini", O_RDONLY)          = 3
lstat("/etc/php.ini", {st_mode=S_IFREG|0644, st_size=69105, ...}) = 0

Upvotes: 11

MikeiLL
MikeiLL

Reputation: 6570

On OS X v10.9 (Mavericks), running:

$ php -i | grep 'Configuration File'

Returned:

Configuration File (php.ini) Path => /etc
Loaded Configuration File:         (none)

In the /etc/ directory was:

php.ini.default

(as well as php-fpm.conf.default)

I was able to copy php.ini.default to php.ini, add date.timezone = "US/Central" to the top (right below [php]), and the problem is solved.

(At least the error message is gone.)

Upvotes: 7

Pascal MARTIN
Pascal MARTIN

Reputation: 401182

You can get a full phpinfo() using:

php -i

And, in there, there is the php.ini file used:

$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini

On Windows, use find instead:

php -i | find/i"configuration file"

Upvotes: 409

Mchl
Mchl

Reputation: 62395

Just run php --ini and look for Loaded Configuration File in the output for the location of php.ini used by your CLI.

Upvotes: 1131

Mike Mackintosh
Mike Mackintosh

Reputation: 14245

If you need to pass it to another app, you can do something like:

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)

Upvotes: 7

user142162
user142162

Reputation:

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

Upvotes: 3

Related Questions