Dude, where's my php.ini?

2019-01-01 05:49发布

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.

12条回答
皆成旧梦
2楼-- · 2019-01-01 06:45

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());'
查看更多
路过你的时光
3楼-- · 2019-01-01 06:46
phpinfo();

will tell you its location, or from the command line

php -i
查看更多
查无此人
4楼-- · 2019-01-01 06:47

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}

查看更多
倾城一夜雪
5楼-- · 2019-01-01 06:49

This command should help you to find it

php -r "phpinfo();" | grep php.ini
查看更多
几人难应
6楼-- · 2019-01-01 06:50

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();
查看更多
时光乱了年华
7楼-- · 2019-01-01 06:51

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
查看更多
登录 后发表回答