php MacOsX Sierra 上的 ini 文件在哪里?

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

Where are ini files on MacOsX Sierra?

phpmacos-sierra

提问by sensorario

I've just bought new MacBook Pro. Take a look on what php -i | grep inireturns:

我刚买了新的 MacBook Pro。看看什么php -i | grep ini返回:

prompt> php -i | grep ini
Configuration File (php.ini) Path => /etc
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
user_ini.cache_ttl => 300 => 300
user_ini.filename => .user.ini => .user.ini
Supported handlers => ndbm cdb cdb_make inifile flatfile
init_command_executed_count => 0
init_command_failed_count => 0
com_init_db => 0
Classes => AppendIterator, ArrayIterator, ArrayObject, BadFunctionCallException, BadMethodCallException, CachingIterator, CallbackFilterIterator, DirectoryIterator, DomainException, EmptyIterator, FilesystemIterator, FilterIterator, GlobIterator, InfiniteIterator, InvalidArgumentException, IteratorIterator, LengthException, LimitIterator, LogicException, MultipleIterator, NoRewindIterator, OutOfBoundsException, OutOfRangeException, OverflowException, ParentIterator, RangeException, RecursiveArrayIterator, RecursiveCachingIterator, RecursiveCallbackFilterIterator, RecursiveDirectoryIterator, RecursiveFilterIterator, RecursiveIteratorIterator, RecursiveRegexIterator, RecursiveTreeIterator, RegexIterator, RuntimeException, SplDoublyLinkedList, SplFileInfo, SplFileObject, SplFixedArray, SplHeap, SplMinHeap, SplMaxHeap, SplObjectStorage, SplPriorityQueue, SplQueue, SplStack, SplTempFileObject, UnderflowException, UnexpectedValueException
open sourced by => Epinions.com

And this is what happens when I run php --ini

这就是我跑步时发生的事情 php --ini

prompt> $ php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File:         (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

It seems there current php is not loading any php.ini file. Is it possible?

似乎当前的 php 没有加载任何 php.ini 文件。是否可以?

回答by duskwuff -inactive-

Current versions of Mac OS X do not ship with a php.ini. PHP uses internal defaults for all settings.

当前版本的 Mac OS X 不附带php.ini. PHP 对所有设置使用内部默认值。

There is a sample configuration file installed at /etc/php.ini.default. If you need to customize PHP settings, you can use that file as a template to create a configuration file at /etc/php.ini. PHP will read settings from that file if it's present.

安装了一个示例配置文件/etc/php.ini.default。如果您需要自定义 PHP 设置,您可以使用该文件作为模板在/etc/php.ini. 如果该文件存在,PHP 将从该文件中读取设置。

回答by Bilal Khoukhi

Edit: The following method was tested and I confirm it works on macOS, Linux and Windows' CMD and Bash

编辑:以下方法已经过测试,我确认它适用于 macOS、Linux 和 Windows 的 CMD 和 Bash

All you need to type in the terminal/CMD/Bash is

您只需要在终端/CMD/Bash 中输入

php --ini

It will render something like:

它将呈现如下内容:

Configuration File (php.ini) Path: /usr/local/etc/php/5.6
Loaded Configuration File:         /usr/local/etc/php/5.6/php.ini
Scan for additional .ini files in: /usr/local/etc/php/5.6/conf.d
Additional .ini files parsed:      (none)

回答by Samay

There is a PHP function called php_ini_loaded_file() which returns the path of php.ini which is loaded.

有一个名为 php_ini_loaded_file() 的 PHP 函数,它返回加载的 php.ini 的路径。

Try the code below.

试试下面的代码。

<?php
$inipath = php_ini_loaded_file();

if ($inipath) {
    echo 'Loaded php.ini: ' . $inipath;
} else {
    echo 'A php.ini file is not loaded';
}
?>

回答by Paul J

You can use the findcommand to search the file system for php.ini or anything else. It can take a long time to find it, depending on your file system size. If you want to make it stop searching you can do CTRL-C.

您可以使用该find命令在文件系统中搜索 php.ini 或其他任何内容。可能需要很长时间才能找到它,具体取决于您的文件系统大小。如果你想让它停止搜索,你可以这样做CTRL-C

find / -type f -name php.ini

If you're not root you'll get some permission denied messages, if you want to run as root you can do this.

如果您不是 root,您会收到一些权限被拒绝的消息,如果您想以 root 身份运行,您可以这样做。

sudo find / -type f -name php.ini

Here's a tutorial for find if you're interested in some other examples.

如果您对其他一些示例感兴趣,这里有一个教程。

http://www.tecmint.com/35-practical-examples-of-linux-find-command/

http://www.tecmint.com/35-practical-examples-of-linux-find-command/

回答by Milan Urukalo

php -r "echo php_ini_loaded_file();"

on my machine returns:

在我的机器上返回:

/usr/local/etc/php/7.1/php.ini

;)

;)

回答by Ulysnep

This worked for me in MacOS Sierra with PHP 7.1 installed:

这在安装了 PHP 7.1 的 MacOS Sierra 中对我有用:

  1. Create a php file called phpinfo_temp.php (remember to remove this file when you're done):

    <?php phpinfo(); ?>

  2. Load the file and you'll notice about 7 variables down: "Loaded Configuration File:". This is the php file that is loaded.

  3. Backup the php.ini file before editing:

    sudo cp /usr/local/php5/lib/php.ini /usr/local/php5/lib/php.ini.backup

  4. Then edit php.ini

    sudo nano /usr/local/php5/lib/php.ini

  5. Once you're done editing, restart the apache server

    sudo apachectl restart

  1. 创建一个名为 phpinfo_temp.php 的 php 文件(完成后记得删除这个文件):

    <?php phpinfo(); ?>

  2. 加载文件,您会注意到大约 7 个变量:“加载的配置文件:”。这是加载的php文件。

  3. 编辑前备份 php.ini 文件:

    sudo cp /usr/local/php5/lib/php.ini /usr/local/php5/lib/php.ini.backup

  4. 然后编辑php.ini

    sudo nano /usr/local/php5/lib/php.ini

  5. 完成编辑后,重新启动apache服务器

    sudo apachectl restart

回答by haz

most often the .inifile doesn't exist as is, but it is named .ini.defaultin the /etc.

大多数情况下,该.ini文件并不按原样存在,但它.ini.default/etc.

回答by Daniel Nitu

I'll add an updated answer for anyone dealing with this on MacOS Mojave and PHP 7.1

我将为在 MacOS Mojave 和 PHP 7.1 上处理此问题的任何人添加更新的答案

Running php --iniin the terminal returned this:

php --ini在终端中运行返回:

Configuration File (php.ini) Path: /etc
Loaded Configuration File:         (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

I found the php.ini.defaultfile in /private/etc/, duplicated it and renamed it to php.ini, which now gets loaded properly:

我在 中找到了该php.ini.default文件/private/etc/,将其复制并重命名为php.ini,现在可以正确加载:

Configuration File (php.ini) Path: /etc
Loaded Configuration File:         /etc/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)