php 如何找到命令行使用的php.ini文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2750580/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:33:36  来源:igfitidea点击:

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

phpeasyphp

提问by Amokrane Chentir

I need to enable pdo_mysql in my EasyPhp environment, so I went to php.ini file and uncommented the following line:

我需要在 EasyPhp 环境中启用 pdo_mysql,所以我转到 php.ini 文件并取消注释以下行:

extension=php_pdo_mysql.dll

Unfortunately I still have the same problem. I'm using the CLI so I suppose I need to locate the php.ini file used by the CLI. How can I find it?

不幸的是,我仍然有同样的问题。我正在使用 CLI,所以我想我需要找到 CLI 使用的 php.ini 文件。我怎样才能找到它?

回答by Mchl

Just run php --iniand look for Loaded Configuration Filein output for the location of php.iniused by your CLI

只需运行php --iniLoaded Configuration File在输出中查找php.iniCLI 使用的位置

回答by Pascal MARTIN

You can get a full phpinfo()using :

你可以得到一个完整的phpinfo()使用:

php -i 

And, in there, there is the php.inifile used :

而且,在那里,有php.ini使用的文件:

$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini

On Windows use findinstead:

在 Windows 上find改用:

php -i|find/i"configuration file"

回答by VolkerK

You can use get_cfg_var('cfg_file_path')for that:

您可以使用get_cfg_var('cfg_file_path')

To check whether the system is using a configuration file, try retrieving the value of the cfg_file_path configuration setting. If this is available, a configuration file is being used.
要检查系统是否正在使用配置文件,请尝试检索 cfg_file_path 配置设置的值。如果可用,则说明正在使用配置文件。
与 phpinfo() 不同,它会判断它是否根本没有找到/使用 php.ini。

var_dump( get_cfg_var('cfg_file_path') );

And you can simply setthe location of the php.ini. You're using the command line version, so using the -cparameter you can specifiy the location, e.g.

您可以简单地设置php.ini 的位置。您使用的是命令行版本,因此使用-c参数可以指定位置,例如

php -c /home/me/php.ini -f /home/me/test.php

回答by Sathish

Run php --iniin your terminal, you'll get all details about ini files

php --ini在终端中运行,您将获得有关 ini 文件的所有详细信息

[root@tamilan src]# php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File:         /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed:      /etc/php.d/apc.ini,
/etc/php.d/bcmath.ini,
/etc/php.d/curl.ini,
/etc/php.d/dba.ini,
/etc/php.d/dom.ini,
/etc/php.d/fileinfo.ini,
/etc/php.d/gd.ini,
/etc/php.d/imap.ini,
/etc/php.d/json.ini,
/etc/php.d/mbstring.ini,
/etc/php.d/memcache.ini,
/etc/php.d/mysql.ini,
/etc/php.d/mysqli.ini,
/etc/php.d/pdo.ini,
/etc/php.d/pdo_mysql.ini,
/etc/php.d/pdo_sqlite.ini,
/etc/php.d/phar.ini,
/etc/php.d/posix.ini,
/etc/php.d/sqlite3.ini,
/etc/php.d/ssh2.ini,
/etc/php.d/sysvmsg.ini,
/etc/php.d/sysvsem.ini,
/etc/php.d/sysvshm.ini,
/etc/php.d/wddx.ini,
/etc/php.d/xmlreader.ini,
/etc/php.d/xmlwriter.ini,
/etc/php.d/xsl.ini,
/etc/php.d/zip.ini

For more, use helping command php --helpIt'll display all the possible options.

有关更多信息,请使用帮助命令php --help它会显示所有可能的选项。

回答by thomas-peter

Somtimes things aren't always as they seem when in comes to config files in general. So here I'm applying my usual methods for exploring what files are opened by a process.

有时,在一般的配置文件中,事情并不总是像它们看起来的那样。所以在这里我应用我常用的方法来探索进程打开了哪些文件。

I use a very powerful and useful command-line program called straceto show me what's really going on behind my back!

我使用了一个非常强大且有用的命令行程序strace来向我展示背后到底发生了什么!

$ strace -o strace.log php --version
$ grep php.ini strace.log

Strace digs out kernel (system) calls that your program makes and dumps the output into the file specified by -o

Strace 挖掘出您的程序进行的内核(系统)调用并将输出转储到 -o 指定的文件中

It's easy to use grepto search for occurrences of php.ini in this log. It's pretty obvious looking at the following typical response to see what is going on.

使用grep在此日志中搜索 php.ini 的出现很容易。查看以下典型响应以了解发生了什么是非常明显的。

open("/usr/bin/php.ini", O_RDONLY)      = -1 ENOENT (No such file or directory)
open("/etc/php.ini", O_RDONLY)          = 3
lstat("/etc/php.ini", {st_mode=S_IFREG|0644, st_size=69105, ...}) = 0

回答by Reece45

If you want all the configuration files loaded, this is will tell you:

如果你想加载所有的配置文件,这会告诉你:

php -i | grep "\.ini"

Some systems load things from more than one ini file. On my ubuntu system, it looks like this:

一些系统从多个 ini 文件加载内容。在我的 ubuntu 系统上,它看起来像这样:

$  php -i | grep "\.ini"
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
Scan this dir for additional .ini files => /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/mcrypt.ini,
/etc/php5/cli/conf.d/memcache.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

回答by MikeiLL

On OSX Mavericks, running:

在 OSX Mavericks 上,运行:

$ php -i | grep 'Configuration File'

Returned:

回来:

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

In the /etc/directory was:

/etc/目录中是:

php.ini.default

(as well as php-fpm.conf.default)

(以及php-fpm.conf.default

I was able to copy php.ini.defaultto php.ini, add date.timezone = "US/Central"to the top (right below [php]), and the problem is solved.

我能够复制php.ini.defaultphp.ini,添加date.timezone = "US/Central"到顶部(右下方[php]),问题就解决了。

(At least the error message is gone.)

(至少错误信息消失了。)

回答by Mike Mackintosh

If you need to pass it to another app, you can do something like:

如果您需要将其传递给另一个应用程序,您可以执行以下操作:

php --ini | grep Loaded | cut -d" " -f12

returns the path only. php -c $(php --ini | grep Loaded | cut -d" " -f12)will pass in the config file (useful for fpm)

仅返回路径。php -c $(php --ini | grep Loaded | cut -d" " -f12)将传入配置文件(对 有用fpm

回答by Tim Cooper

From what I remember when I used to use EasyPHP, the php.ini file is either in C:\Windows\or C:\Windows\System32

我记得以前使用 EasyPHP 时,php.ini 文件在C:\Windows\C:\Windows\System32

回答by Han Van Pham

Do

find / -type f -name "php.ini" 

This will output all files named php.ini.

这将输出所有名为php.ini.

Find out which one you're using, usually apache2/php.ini

找出您通常使用的是哪一种 apache2/php.ini