我在哪里可以找到php.ini?

发布于 2025-01-22 06:54:16 字数 373 浏览 2 评论 0 原文

今天,我需要安装IBM DB2库。我完成了所有步骤,直到进行安装,然后在 $ php_home/lib/extensions/somecomplecatedName/ibm_db2.so 中找到了ibm_db2.so。

最大的收获是最后一步是配置文件 php.ini ,但是没有任何 任何 php.ini 我的系统上的文件。 PHP当然可以正常工作,除了这个新的IBM_DB2 ThingAmajig。 (我尝试了一个小的php脚本,该脚本失败并指出IBM_DB2函数不可用。)

如何查找或设置php.ini文件,以便我可以启用所需的库?

Today I needed to install the IBM DB2 library. I went through all the steps up to make install, and I found ibm_db2.so in $PHP_HOME/lib/extensions/somecomplicatedname/ibm_db2.so.

The great catch is the last step is to configure file php.ini, but there aren't any php.ini files on my system. PHP works fine, except of course for this newfangled ibm_db2 thingamajig. (I tried a small PHP script which fails and indicates that the ibm_db2 functions are not available.)

How would I go about finding or setting up the php.ini file so that I can enable the library I need?

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

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

发布评论

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

评论(15

淡墨 2025-01-29 06:54:16

在命令行执行:

php --ini

您将获得类似的内容:

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

这是我本地的Dev-Machine。但是,第二行是有趣的。如果没有提及,请看看第一个。这就是PHP寻找 php.ini 文件的路径。

您可以使用 phpinfo()在脚本中打电话,然后致电并致电它带有浏览器。在输出的第一个块中提到了它。 php -i 在命令行中执行了相同的操作,但这很不舒服。

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

You can grep the same information using phpinfo() in a script and call it with a browser. It’s mentioned in the first block of the output. php -i does the same for the command line, but it’s quite uncomfortable.

小清晰的声音 2025-01-29 06:54:16

找到此问题的最佳方法是:

创建一个php( .php )文件,并添加以下代码:

<?php phpinfo(); ?>

并将其打开在浏览器中。它将显示实际正在阅读的文件!

OP的更新:

  1. 先前接受的答案对您来说更方便,但这并不总是正确的。请参阅有关该答案的评论。
  2. 还请注意,更方便的替代&lt;?php echo php_ini_loaded_file(); ?

The best way to find this is:

Create a PHP (.php) file and add the following code:

<?php phpinfo(); ?>

and open it in a browser. It will show the file which is actually being read!

Updates by the 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.
柠北森屋 2025-01-29 06:54:16

这对我有用:

php -i | grep 'php.ini'

您应该看到类似的内容:

Loaded Configuration File => /usr/local/lib/php.ini

PS

仅获得php.ini路径,使用:

php -i | grep /.+/php.ini -oE

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.ini path, use:

php -i | grep /.+/php.ini -oE
桃扇骨 2025-01-29 06:54:16

在命令窗口中,键入

php --ini

它将显示类似的路径:

Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File:         /usr/local/lib/php.ini

如果上述命令不起作用,请使用以下方式:

echo phpinfo();

In a 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();
能否归途做我良人 2025-01-29 06:54:16

使用以下命令在Linux上找到 php.ini 文件路径。

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

或以此方式尝试:

php --ini

它显示路径结果。

Use the following command to find the php.ini file path on Linux.

locate php.ini

Output:

/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 other way:

php --ini

It shows the path result.

青芜 2025-01-29 06:54:16

此命令应帮助您找到它

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

This command should help you to find it

php -r "phpinfo();" | grep php.ini
天生の放荡 2025-01-29 06:54:16

php附带两个本机函数以显示加载哪个配置文件:

根据您的设置, apache cli 可能会使用不同的.INI文件, 。以下是两个解决方案:

apache:

只需在php(.php)文件中添加以下内容,然后在浏览器中打开它:

print php_ini_loaded_file();
print_r(php_ini_scanned_files());

CLI:

COPY-PASTE在您的终端中:

php -r 'print php_ini_loaded_file(); print_r(php_ini_scanned_files());'

PHP comes with two native functions to show which configuration 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 (.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());'
涫野音 2025-01-29 06:54:16
phpinfo();

会告诉您其位置或从命令行告诉您的位置

php -i
phpinfo();

will tell you its location, or from the command line

php -i
人│生佛魔见 2025-01-29 06:54:16

尝试以下解决方案之一

  1. 在您的终端中,类型 find/-name“ php.ini”

  2. 在您的终端中,类型 php -i | Grep php.ini 。它应该显示文件路径为“配置文件(php.ini)路径=&gt;/etc”

  3. ” href =“ https://en.wikipedia.org/wiki/notepad_%28software%29” rel =“ noreferrer”> Notepad )和插入 phpinfo() &lt;?php 在新线路上。这将告诉您 php.ini 位置。

  4. 您也可以在交互式模式下与PHP交谈。只需在终端和类型 phpinfo(); 中键入 php -a

Try one of these solutions

  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 of your PHP files, open it in a editor (Notepad) and insert phpinfo(); after <?php on a new line. 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 the PHP interpreter initiated.

紫瑟鸿黎 2025-01-29 06:54:16

在命令行中运行此:

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

Run this in the command line:

php -r "echo php_ini_loaded_file().PHP_EOL;"
凉宸 2025-01-29 06:54:16
find / -name php.ini

嘿...对我有用!

find / -name php.ini

Hey... it worked for me!

暗藏城府 2025-01-29 06:54:16

您可以使用以下内容获取有关配置文件的更多信息:

$ -> php -i | ack config # Use fgrep -i if you don't have ack

Configure Command =>  './configure'  ...
Loaded Configuration File => /path/to/php.ini

You can get more information about your configuration 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
负佳期 2025-01-29 06:54:16

对于 sapi :php-fppm:php-fppm

无需创建一个php。 info 文件(无论如何,将其留给世界都不是一个好政策)。在命令行:

php-fpm -i | more

输出中的某个地方,它将显示以下行:

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

这是一个更完整的说明:
”如何在没有info.php 的情况下找出PHP配置参数

For SAPI: php-fpm

There isn't any 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:
How to Figure out Your PHP Configuration Parameters without info.php

我是男神闪亮亮 2025-01-29 06:54:16

根据此答案,如 php 7 常规php.ini文件是删除,并使用 php.ini-raproduction php.ini-devlopment

因此,在我的情况下不存在不存在的php.ini(我已经安装了php 8.1),使用 php.ini-production ,它位于php安装文件夹中(类似于: c c。 :\ php-8.1.5 )并创建一个文件并将其命名 php.ini ,然后在此新< php.ini-production 复制内容代码> php.ini 。

according to this answer, as of PHP 7 the regular php.ini file was removed and added with php.ini-production and php.ini-devlopment.

so instead of php.ini which does not exist in my case (I've installed php 8.1), use php.ini-production and it's located in php installation folder (something like: C:\PHP-8.1.5) and create a file and name it php.ini and then copy contents of php.ini-production in this new php.ini.

许你一世情深 2025-01-29 06:54:16

检查INI配置文件

apache /etc/php/xy/apache2/php.ini 的路径
nginx /etc/php/xy/fpm/php.ini

xy = php版本使用(可以在不同的路径中以获取更多路径)

PATHS to check for ini config file

apache /etc/php/X.Y/apache2/php.ini
nginx /etc/php/X.Y/fpm/php.ini

XY=PHP Version used (could be in different paths for more paths)

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