By necromancer


2011-12-30 22:20:06 8 Comments

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 comments

@Max 2020-06-24 21:30:10

Run this in the command line:

php -r "echo php_ini_loaded_file().PHP_EOL;"

@cherankrish 2019-06-07 16:57:07

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.

@necromancer 2019-09-18 09:18:07

points 1, 2, and 4 are vulnerable to multiple installation problems; there are already great answers. no need to add an answer that doesn't add anything here.

@coderama 2013-04-02 11:48:31

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

@KingCrunch 2013-08-08 20:30:47

This only works, if there is a php.ini, which is exactly the problem: If there is none, you still don't know where to look at, or where to place a new one.

@coderama 2013-12-30 14:46:24

I've never come across a situation where there is no php.ini file.

@Leo Galleguillos 2014-06-13 18:35:21

Running this command gives me Configuration File (php.ini) Path => /usr/lib, but running <?php phpinfo(); ?> gives me Loaded Configuration File: /etc/php.ini. So, phpinfo() was more reliable in my case.

@Andrea Moro 2014-06-23 13:26:34

This is not entirely correct. Every framework that uses the PHP language has it's own php.ini file. If you call that line from the command line, you will probably end up receiving something like /var/php5/cli/php.ini which is not the file used when running PHP on a web environment. For that file, you should look into the apache2 folder.

@Sakthi Karthik 2016-02-17 10:58:28

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

[[email protected] ~]# 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

[[email protected] ~]# php --ini
its shows the path result

@lxg 2016-02-17 11:09:28

This is inferior to methods like php -i | grep 'php.ini', because it finds any php.ini and doesn’t tell you which one your PHP installation uses. Also, it may give wrong results when the locate DB is not up to date.

@Tejas 2013-06-19 07:32:29

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.

@Dan 2014-05-30 23:44:25

This should be the accepted answer. If you have CLI installed and have apache running then it may have its own ini file (as my system does). Using the accepted answer returns what the CLI is using rather than apache's.

@necromancer 2014-09-13 21:02:03

@Dan Yes, you are right. I am changing the accepted answer to this one because the problem you mention was also encountered somebody in practice (who commented on the previously accepted answer). (By the way, if you had commented on the question I would have fixed this problem sooner.)

@svenyonson 2015-01-23 18:33:10

This does not work on my installation. Typo? Should be <?php phpinfo(); ?>

@jgraup 2016-02-02 19:35:01

php -r \@phpinfo\(\)\; works for me php -r \@phpinfo\(\)\; | grep 'PHP Version' -m 1 to pull specific info

@Ates Goral 2017-06-27 15:55:58

@zylstra Try: <?php echo php_ini_loaded_file(); ?>

@fantastory 2020-01-30 15:22:53

the problem with this is when php does not want to load

@Cragmonkey 2017-01-04 04:37:18

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}

@necromancer 2017-01-14 21:51:46

see this instead: stackoverflow.com/a/24342463/621338 instead of grepping it out, which is brittle if the text changes, you could have php print just the file name and use it in a bash script without complicated stuff like the above.

@NightKnight on Cloudinsidr.com 2015-11-17 15:16:51

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/

@bibliophilsagar 2015-10-09 12:36:25

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();

@Rimantas Jacikevicius 2015-01-09 15:41:02

This command should help you to find it

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

@Andrew Allbright 2017-10-16 20:38:18

I like this a lot more than some of the other answers. It doesn't require that I create, locate a php file with those contents and load up the page in the browser.

@Banned_User 2014-12-22 07:22:11

find / -name php.ini

Hey... it worked for me!

@necromancer 2014-12-23 10:07:17

for one, it takes a while; for two, if you have more than one, how do you know which is the one actually in use?

@Banned_User 2014-12-25 10:31:08

True, php --ini works, but this is just another option :) There is usually a /etc/php5/cli/php.ini /etc/php5/apache2/php.ini /etc/php5/cgi/php.ini and usually which one you want is pretty obvious. (cli, apache, cgi)

@user8389458 2018-03-10 23:14:53

This is not a good solution, because we are not intended to find all the php.ini file on disk.

@Creaforge 2014-06-21 14:19:26

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());'

@necromancer 2017-06-10 00:51:23

Under-appreciated, thorough, and (almost) correct answer. I almost switched this to the correct answer but I am worried that php_ini_loaded_file may not always be available.

@necromancer 2017-06-10 00:52:18

@zylstra what was your php version? the docs for php_ini_loaded_file say php version >= 5.2.4

@zylstra 2017-06-11 16:54:19

@necromancer Not sure now. Forgot which system I was checking. :/

@KingCrunch 2011-12-30 22:22:45

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.

@necromancer 2011-12-30 22:40:22

accepting oldest and previously the simplest answer (SO forces me to wait a while before accepting). thanks for the expansion which will probably help the next person looking for information. for me the 2nd line said (none), and everything worked fine after putting a php.ini file in the path on the first line. thanks!

@thecommonthread 2014-06-17 18:24:04

I used this command and edited the php.ini file that it directed me too and my PHP settings were not changing and I realized it was not giving me the correct php.ini file. I tried using the phpinfo() PHP function and it give me the actual correct location of the php.ini I needed to edit. I think this is very important and I hope this helps someone.

@Adam 2014-06-19 14:38:57

/etc/php5/apache2/php.ini

@necromancer 2014-09-13 21:06:03

@thecommonthread Thank you for pointing out the problem you encountered in practice. I have changed the accepted answer to one that highlights creating a .php file. By the way, if you comment on the question then I get notified and I can fix the problem sooner.

@Pacerier 2015-06-24 11:16:09

@KingCrunch, Are you sure this is going to work when you have more than one PHP installation?

@KingCrunch 2015-06-24 13:50:11

@Pacerier Yes. Just make sure you execute the right executable: /path/to/one/php --ini and /path/to/another/php --ini.

@Pacerier 2015-06-25 02:25:45

@KingCrunch, Then what about thecommonthread's comment above?

@KingCrunch 2015-06-26 07:05:29

@Pacerier This has nothing to do with different PHP installations, but the different SAPIs can use different ini files. I don't use the apache module, but as far as I remember I think there is no way around a phpinfo.php-like file. With FPM you can at least use php5-fpm -i | grep '\.ini'. Usually you use this two or three times and at the end of the day you know where the files are ;)

@CodeBrauer 2015-08-18 10:01:56

Also on some lamp stacks this will return you only the php-cli php-ini.

@Chris Beeley 2019-07-07 11:03:13

I ended up editing the wrong ini file too, wasting an hour. This may be my own stupidity, but this is a warning to people like me- if it's not working create a <?php phpinfo(); ?> as above because that fixed it for me

@user557846 2011-12-30 22:24:05

phpinfo();

will tell you its location, or from the command line

php -i

@Mike Purcell 2011-12-30 22:25:22

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

Related Questions

Sponsored Content

19 Answered Questions

[SOLVED] How can I profile C++ code running on Linux?

  • 2008-12-17 20:29:24
  • Gabriel Isenberg
  • 540602 View
  • 1863 Score
  • 19 Answer
  • Tags:   c++ linux profiling

38 Answered Questions

[SOLVED] How to exclude a directory in find . command

  • 2010-11-17 22:57:02
  • helion3
  • 1064135 View
  • 1440 Score
  • 38 Answer
  • Tags:   linux shell find

50 Answered Questions

[SOLVED] How do I find all files containing specific text on Linux?

7 Answered Questions

[SOLVED] where can I find the php.ini for php-cli

  • 2010-06-16 20:55:52
  • Elzo Valugi
  • 70628 View
  • 68 Score
  • 7 Answer
  • Tags:   php php-ini

28 Answered Questions

[SOLVED] How can I prevent SQL injection in PHP?

16 Answered Questions

4 Answered Questions

[SOLVED] How can I use grep to show just filenames on Linux?

  • 2011-07-09 22:24:53
  • cwd
  • 681495 View
  • 1115 Score
  • 4 Answer
  • Tags:   linux grep

10 Answered Questions

[SOLVED] Given two directory trees, how can I find out which files differ by content?

14 Answered Questions

[SOLVED] How to find the php.ini file used by the command line?

  • 2010-05-01 15:53:00
  • Amokrane Chentir
  • 407634 View
  • 403 Score
  • 14 Answer
  • Tags:   php easyphp

Sponsored Content