963
votes

A few years ago I installed Apache 2.2x and PHP 5.3.1 on a Linux server I maintain. I used .tar.gz's and built them as instructed (instead of rpms and what-have-you). And all was fine.

Today I need to install this which seems like a PHP library. I went through all the steps up to make install, and I find ibm_db2.so in $PHP_HOME/lib/extensions/somecomplicatedname/ibm_db2.so

The great catch is the last step is to configure php.ini but there is NO php.ini on my system. Horror of horrors. PHP works fine, except of course for this new-fangled ibm_db2 thingamagic that I want to use so somebody can use a GUI to tinker with DB2. (I tried a small php script which fails and indicates that the ibm_db2 functions are not available).

I have to deal with PHP once every few years, so please enlighten me at a very basic level about what I could do to enable web-based GUI access to DB2.

14
90% of the time it's /etc/php5/apache2/php.iniAdam
The premise of the question is wrong. "there is NO php.ini on my system" No, you simply failed to locate it. Speaking of which, locate php.ini will tell you in mere moments where the file is on your system.Lightness Races in Orbit
@Adam: unless it isn't PHP5 ;)Line
@line yeah my comment isn't too relevant anymore, although didn't realise the amount of upvotes!Adam

14 Answers

514
votes

Best way to find this is: create a php file and add the following code:

<?php phpinfo(); ?>

and open it in browser, it will show the file which is actually being read!

Updates by OP:

  1. The previously accepted answer is likely to be faster and more convenient for you, but it is not always correct. See comments on that answer.
  2. Please also note the more convenient alternative <?php echo php_ini_loaded_file(); ?> mentioned in this answer.
922
votes

On the command line execute:

php --ini

You will get something like:

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/curl.ini,
/etc/php5/cli/conf.d/pdo.ini,
/etc/php5/cli/conf.d/pdo_sqlite.ini,
/etc/php5/cli/conf.d/sqlite.ini,
/etc/php5/cli/conf.d/sqlite3.ini,
/etc/php5/cli/conf.d/xdebug.ini,
/etc/php5/cli/conf.d/xsl.ini

That's from my local dev-machine. However, the second line is the interesting one. If there is nothing mentioned, have a look at the first one. That is the path, where PHP looks for the php.ini.

You can grep the same information using phpinfo() in a script and call it with a browser. Its mentioned in the first block of the output. php -i does the same for the command line, but its quite uncomfortable.

153
votes

This works for me:

php -i | grep 'php.ini'

You should see something like:

Loaded Configuration File => /usr/local/lib/php.ini

p.s. To get only the php.inin path

php -i | grep /.+/php.ini -oE
67
votes

In command window type

php --ini

It will show you the path something like

Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File:         /usr/local/lib/php.ini

If the above command does not work then use this

echo phpinfo();
34
votes

This command should help you to find it

php -r "phpinfo();" | grep php.ini
30
votes

Use the following commands to find the php.ini file path in linux.

[root@AnyDirectory ~]# locate php.ini
/etc/php.ini
/etc/php.ini.rpmnew
/usr/share/doc/php-common-5.4.45/php.ini-development
/usr/share/doc/php-common-5.4.45/php.ini-production


or try this another way

[root@AnyDirectory ~]# php --ini
its shows the path result

26
votes
phpinfo();

will tell you its location, or from the command line

php -i
24
votes

PHP comes with two native functions to show which config file is loaded :

Depending on your setup, Apache and CLI might use different ini files. Here are the two solutions :

Apache :

Just add the following in a php file and open it in your browser

print php_ini_loaded_file();
print_r(php_ini_scanned_files());

CLI :

Copy-paste in your terminal :

php -r 'print php_ini_loaded_file(); print_r(php_ini_scanned_files());'
19
votes

Run this in the command line:

php -r "echo php_ini_loaded_file().PHP_EOL;"
8
votes
find / -name php.ini

Hey... it worked for me!

8
votes

Try one of this solution

  1. In your terminal type find / -name "php.ini"

  2. In your terminal type php -i | grep php.ini . It should show the file path as Configuration File (php.ini) Path => /etc

  3. If you can access one your php files , open it in a editor (notepad) and insert below code after <?php in a new line phpinfo(); This will tell you the php.ini location
  4. You can also talk to php in interactive mode. Just type php -a in the terminal and type phpinfo(); after php initiated.
4
votes

You can get more info about your config files using something like:

$ -> php -i | ack config # Use fgrep -i if you don't have ack

Configure Command =>  './configure'  ...
Loaded Configuration File => /path/to/php.ini
4
votes

For SAPI: php-fpm

There is no need to create a php.info file (it is not a good policy to leave it for the world to read anyway). On the command line:

php-fpm -i | more

Somewhere in its output, it will show this line:

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

Here is a more complete explanation: https://www.cloudinsidr.com/content/how-to-figure-out-your-php-configuration-parameters-without-info-php/

-1
votes

There are several valid ways already mentioned for locating the php.ini file, but if you came across this page because you want to do something with it in a bash script:

path_php_ini="$(php -i | grep 'Configuration File (php.ini) Path' | grep -oP '(?<=\=\>\s).*')" echo ${path_php_ini}