72

It appears that the php command line is using a different php.ini from the main php interpreter. I am using Ubuntu 10.4. My problem is that in the main php.ini I have included an extra path for an external library, but in the cli version this is not present, and so I have a path inclusion error.

thanks

William Perron
  • 485
  • 7
  • 16
Elzo Valugi
  • 27,240
  • 15
  • 95
  • 114
  • possible duplicate of [How to find the php.ini file used by the command line?](http://stackoverflow.com/questions/2750580/how-to-find-the-php-ini-file-used-by-the-command-line) – Wrikken Jan 30 '14 at 18:49

7 Answers7

162

Just ask PHP:

php -i |grep php\.ini
Black
  • 18,150
  • 39
  • 158
  • 271
timdev
  • 61,857
  • 6
  • 82
  • 92
  • Better answer than mine, as it'll work for non-default and non-Ubuntu uses. – ceejayoz Jun 16 '10 at 21:03
  • I get `Configuration File (php.ini) Path => /usr/local/lib64`, but the php.ini is not in this folder. – Black Jun 22 '20 at 15:44
  • If you don't see `php.ini` it means it doesn't exist and PHP takes default values. You can create new `php.ini` file into this directory. – Jsowa Oct 07 '20 at 20:39
  • before creating a new one, check the [answer below](https://stackoverflow.com/a/3057175/5011027) as there could be another file somewhere else – til Mar 28 '22 at 09:42
72

Better yet: $ php --ini

This will also show all extra *.ini files loaded (usually hanging around in some conf.d dir in debian):

Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File: /etc/php5/cli/php.ini
Scan for additional .ini files in: /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/geoip.ini,
/etc/php5/cli/conf.d/imagick.ini,
/etc/php5/cli/conf.d/imap.ini,
/etc/php5/cli/conf.d/ldap.ini,
/etc/php5/cli/conf.d/memcache.ini,
/etc/php5/cli/conf.d/memcached.ini,
/etc/php5/cli/conf.d/ming.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,
/etc/php5/cli/conf.d/pdo_sqlite.ini,
/etc/php5/cli/conf.d/snmp.ini,
/etc/php5/cli/conf.d/sqlite.ini,
/etc/php5/cli/conf.d/sqlite3.ini,
/etc/php5/cli/conf.d/suhosin.ini,
/etc/php5/cli/conf.d/tidy.ini,
/etc/php5/cli/conf.d/xdebug.ini,
/etc/php5/cli/conf.d/xsl.ini

Note that this was about php-cli, php-cgi does not have this afaik.

Wrikken
  • 69,272
  • 8
  • 97
  • 136
  • A note about all the `conf.d` files - in Ubuntu, that folder is a symlink, so they're shared across all PHP uses. – ceejayoz Jun 16 '10 at 21:16
  • As it is per default in Debian, assuming one installed from the normal repositories. – Wrikken Jun 16 '10 at 21:22
8

At my last job, I got in the habit of specifying my ini file on every execution...

C:\php\cli\php.exe -c C:\php\php.ini myscript.php
Fosco
  • 38,138
  • 7
  • 87
  • 101
  • Interesting. I like it. I just used this now for one of my cron jobs with a custom php.ini file. – Mike Dec 06 '11 at 23:58
3

You can find php.ini using the below command. in LINUX

find / -name php.ini

or

locate php.ini
Nanhe Kumar
  • 15,498
  • 5
  • 79
  • 71
1

/etc/php5/cli/php.ini

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
0

Interesting in windows is that in both tests (on apache with phpinfo() and in cli with php --ini), the configuration file path is c:\windows. More info here

Timo
  • 2,922
  • 3
  • 29
  • 28
-4

I had the same problem. Simply check owner and permissions from every files in /etc/php5/conf.d/. It has to be owned by root and readeable by anymone.