Linux 我在哪里可以找到 php.ini?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8684609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where can I find php.ini?
提问by necromancer
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.
几年前,我在维护的 Linux 服务器上安装了 Apache 2.2x 和 PHP 5.3.1。我使用 .tar.gz's 并按照指示构建它们(而不是 rpms 和 what-have-you)。一切都很好。
Today I need to install thiswhich 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
今天我需要安装它,它看起来像一个 PHP 库。我完成了所有步骤以进行安装,我在其中找到了 ibm_db2.so$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).
最大的收获是最后一步是配置 php.ini,但我的系统上没有 php.ini。恐怖的恐怖。PHP 工作正常,当然除了我想使用的这个新奇的 ibm_db2 thingamagic 以便有人可以使用 GUI 来修补DB2
. (我尝试了一个小的 php 脚本,该脚本失败并表明 ibm_db2 函数不可用)。
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
.
我必须每隔几年处理一次 PHP,所以请在非常基本的层面上启发我,让我知道我可以做些什么来启用基于 Web 的 GUI 访问DB2
.
采纳答案by Tejas
Best way to find this is: create a php file and add the following code:
找到它的最佳方法是:创建一个 php 文件并添加以下代码:
<?php phpinfo(); ?>
and open it in browser, it will show the file which is actually being read!
并在浏览器中打开它,它会显示实际正在读取的文件!
Updates by OP:
OP 更新:
- The previously accepted answeris likely to be faster and more convenient for you, but it is not always correct. See comments on that answer.
- Please also note the more convenient alternative
<?php echo php_ini_loaded_file(); ?>
mentioned in this answer.
回答by KingCrunch
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
.
那是来自我本地的开发机器。然而,第二行是有趣的。如果没有提到任何内容,请查看第一个。这就是 PHP 在其中查找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.
您可以phpinfo()
在脚本中使用 grep 相同的信息并使用浏览器调用它。它在输出的第一个块中提到。php -i
对命令行做同样的事情,但它很不舒服。
回答by KingCrunch
phpinfo();
will tell you its location, or from the command line
会告诉你它的位置,或者从命令行
php -i
回答by Mike Purcell
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
回答by coderama
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
ps 只获取php.inin路径
php -i | grep /.+/php.ini -oE
回答by Creaforge
PHP comes with two native functions to show which config file is loaded :
PHP 带有两个本机函数来显示加载了哪个配置文件:
- php_ini_loaded_filereturn the loaded ini file
- php_ini_scanned_filesreturn a list of .ini files parsed from the additional ini dir
- php_ini_loaded_file返回加载的ini文件
- php_ini_scanned_files返回从附加 ini 目录解析的 .ini 文件列表
Depending on your setup, Apacheand CLImight use different ini files. Here are the two solutions :
根据您的设置,Apache和CLI可能使用不同的 ini 文件。以下是两种解决方案:
Apache :
阿帕奇:
Just add the following in a php file and open it in your browser
只需在 php 文件中添加以下内容并在浏览器中打开它
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());'
回答by Banned_User
find / -name php.ini
Hey... it worked for me!
嘿...它对我有用!
回答by Rimantas Jacikevicius
This command should help you to find it
这个命令应该可以帮助你找到它
php -r "phpinfo();" | grep php.ini
回答by bibliophilsagar
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();
回答by NightKnight on Cloudinsidr.com
For SAPI: php-fpm
对于 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.info 文件(无论如何将其留给全世界阅读并不是一个好策略)。在命令行上:
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/
这里有一个更完整的解释:https: //www.cloudinsidr.com/content/how-to-figure-out-your-php-configuration-parameters-without-info-php/