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

发布于 2024-08-31 04:05:26 字数 283 浏览 3 评论 0原文

我需要在我的 EasyPHP 环境中启用 pdo_mysql,所以我去了php.ini 文件并取消注释以下行:

extension=php_pdo_mysql.dll

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

笑咖 2024-09-07 04:05:26

只需运行 php --ini 并在输出中查找 加载的配置文件,以获取 CLI 使用的 php.ini 的位置。

Just run php --ini and look for Loaded Configuration File in the output for the location of php.ini used by your CLI.

一口甜 2024-09-07 04:05:26

您可以使用以下方法获取完整的 phpinfo()

php -i

并且,其中使用了 php.ini 文件:

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

在 Windows 上,使用 查找 改为:

php -i | find/i"configuration file"

You can get a full phpinfo() using:

php -i

And, in there, there is the php.ini file used:

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

On Windows, use find instead:

php -i | find/i"configuration file"
音盲 2024-09-07 04:05:26

您可以使用 get_cfg_var('cfg_file_path') 来实现:

要检查系统是否正在使用配置文件,尝试检索 cfg_file_path 配置设置的值。如果可用,则正在使用配置文件。

Unlike phpinfo() it will tell if it didn't find/use a php.ini at all.

var_dump( get_cfg_var('cfg_file_path') );

您只需设置 php.ini 的位置即可。您使用的是命令行版本,因此使用 -c 参数您可以指定此特定运行的位置,例如

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

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

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.

Unlike phpinfo() it will tell if it didn't find/use a php.ini at all.

var_dump( get_cfg_var('cfg_file_path') );

And you can simply set the location of the php.ini. You're using the command line version, so using the -c parameter you can specify the location for this particular run, e.g.

php -c /home/me/php.ini -f /home/me/test.php
百思不得你姐 2024-09-07 04:05:26

在终端中运行 php --ini,您将获得有关 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

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

Run php --ini in your terminal, and you'll get all details about ini files:

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 --help. It'll display all the possible options.

多彩岁月 2024-09-07 04:05:26

有时,一般来说,配置文件的情况并不总是像看上去的那样。因此,在这里我将应用常用方法来探索进程打开哪些文件。

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

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

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

使用 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

Sometimes things aren't always as they seem when in comes to configuration 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 strace to show me what's really going on behind my back!

$ 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.

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

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
鹤仙姿 2024-09-07 04:05:26

如果您想要加载所有配置文件,这将告诉您:

php -i | grep "\.ini"

有些系统从多个 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

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:

php -i | grep "\.ini"

Output

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
苍景流年 2024-09-07 04:05:26

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

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

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

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)

初熏 2024-09-07 04:05:26

OS X v10.9 (Mavericks) 上,运行:

$ php -i | grep 'Configuration File'

返回:

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

中/etc/ 目录是:(

php.ini.default

以及 php-fpm.conf.default

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

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

On OS X v10.9 (Mavericks), running:

$ php -i | grep 'Configuration File'

Returned:

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

In the /etc/ directory was:

php.ini.default

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

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

(At least the error message is gone.)

难理解 2024-09-07 04:05:26

现在最简单的方法是使用 PHP 配置:

php-config --ini-dir

输出:

/usr/local/etc/php/7.4/conf.d

您可以在那里找到更多内容。 --help 子命令(macOS 本地安装):

php-config --help

输出:

Usage: /usr/local/bin/php-config [OPTION]
Options:
  --prefixUsage: /usr/local/bin/php-config [OPTION]
Options:
  --prefix            [/usr/local/Cellar/php/7.4.11]
  --includes          [-I/usr/local/Cellar/php/7.4.11/include/php - …ETC…]
  --ldflags           [ -L/usr/local/Cellar/krb5/1.18.2/lib -…ETC…]
  --libs              [ -ltidy -largon2 …ETC… ]
  --extension-dir     [/usr/local/Cellar/php/7.4.11/pecl/20190902]
  --include-dir       [/usr/local/Cellar/php/7.4.11/include/php]
  --man-dir           [/usr/local/Cellar/php/7.4.11/share/man]
  --php-binary        [/usr/local/Cellar/php/7.4.11/bin/php]
  --php-sapis         [ apache2handler cli fpm phpdbg cgi]
  --ini-path          [/usr/local/etc/php/7.4]
  --ini-dir           [/usr/local/etc/php/7.4/conf.d]
  --configure-options [--prefix=/usr/local/Cellar/php/7.4.11 --…ETC…]
  --version           [7.4.11]
  --vernum            [70411]

The easiest way nowadays is to use PHP configure:

php-config --ini-dir

Output:

/usr/local/etc/php/7.4/conf.d

There's more you can find there. The --help sub command (macOS local install):

php-config --help

Output:

Usage: /usr/local/bin/php-config [OPTION]
Options:
  --prefixUsage: /usr/local/bin/php-config [OPTION]
Options:
  --prefix            [/usr/local/Cellar/php/7.4.11]
  --includes          [-I/usr/local/Cellar/php/7.4.11/include/php - …ETC…]
  --ldflags           [ -L/usr/local/Cellar/krb5/1.18.2/lib -…ETC…]
  --libs              [ -ltidy -largon2 …ETC… ]
  --extension-dir     [/usr/local/Cellar/php/7.4.11/pecl/20190902]
  --include-dir       [/usr/local/Cellar/php/7.4.11/include/php]
  --man-dir           [/usr/local/Cellar/php/7.4.11/share/man]
  --php-binary        [/usr/local/Cellar/php/7.4.11/bin/php]
  --php-sapis         [ apache2handler cli fpm phpdbg cgi]
  --ini-path          [/usr/local/etc/php/7.4]
  --ini-dir           [/usr/local/etc/php/7.4/conf.d]
  --configure-options [--prefix=/usr/local/Cellar/php/7.4.11 --…ETC…]
  --version           [7.4.11]
  --vernum            [70411]
始终不够爱げ你 2024-09-07 04:05:26

如果它可以帮助大家,请尝试一下:

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

这将输出名为 php.ini 的所有文件。

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

Try this if it could help you all:

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

This will output all files named php.ini.

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

软糯酥胸 2024-09-07 04:05:26

我记得当我使用 EasyPHP 时,php.ini 文件位于 C:\Windows\C:\Windows\System32

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

枫以 2024-09-07 04:05:26

在 Linux 上,它通常位于 /usr/bin/php

要查找在寡妇电脑上的 CLI 中加载的 php.ini,请运行:

php.exe -i | grep "php.ini"

在此处输入图像描述

您可以使用以下命令本地化 PHP 安装文件夹:

which php

在此处输入图像描述

whereis php

/c/larragon/bin/php/php-7.4.19-Win32-vc15-x64/php

On Linux it is usually under /usr/bin/php

To find php.ini loaded in CLI on widows, run:

php.exe -i | grep "php.ini"

enter image description here

Ps. You can localize PHP installation folder with:

which php

enter image description here

or

whereis php

/c/laragon/bin/php/php-7.4.19-Win32-vc15-x64/php

国际总奸 2024-09-07 04:05:26

由于 PHP 对 HTTP(S) 和 CLI(控制台命令行)模式使用不同的 php.ini 路径,最简单的方法是找出真正加载的 php.ini 文件将 phpinfo() 输出保存到本地文件中:

php -i >> phpinfo-cli.txt

打开保存的文件并保存找到行加载的配置文件。它将包含实际加载的 php.ini 文件的路径,例如:

Loaded Configuration File => D:\wamp\bin\php\php7.4.1\php.ini

上面假设 PHP 已正确安装,例如在 Windows 上包含在 PATH env 中。多变的。

Since PHP uses different php.ini paths for HTTP(S) and CLI (console command line) mode, easiest way is to find out really loaded php.ini file is by saving phpinfo() output into local file:

php -i >> phpinfo-cli.txt

Open saved file & find row Loaded Configuration File. It will contain path to actually loaded php.ini file e.g.:

Loaded Configuration File => D:\wamp\bin\php\php7.4.1\php.ini

The above assumes that PHP is properly installed, e.g. on Windows included in PATH env. variable.

瞳孔里扚悲伤 2024-09-07 04:05:26

在 Docker 容器中,“phpmyadmin/phpmyadmin” 。没有任何 php.ini 文件。但有两个文件:php.ini-debugphp.ini-product

要解决此问题,只需将其中一个文件重命名为 php.ini 并重新启动 Docker 容器即可。

In a Docker container, "phpmyadmin/phpmyadmin". there isn't any php.ini file. But there are two files: php.ini-debug and php.ini-production.

To solve the problem, simply rename one of the files to php.ini and restart the Docker container.

玩心态 2024-09-07 04:05:26

php -r 'var_dump(get_cfg_var("cfg_file_path"));'

使用 PHP!

php -r 'var_dump(get_cfg_var("cfg_file_path"));'

Use PHP!

自此以后,行同陌路 2024-09-07 04:05:26

命令行没有使用 php.ini。您必须将文件从 ...EasyPHP-<>\apache\php.ini 复制到 ...EasyPHP-<> \php\php.ini 然后编辑 php 目录中的那个。

参考:

There is no php.ini used by the command line. You have to copy the file from ...EasyPHP-<<version>>\apache\php.ini to ...EasyPHP-<<version>>\php\php.ini and then edit the one in the php directory.

Reference:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文