问题
I've just bought new MacBook Pro. Take a look on what php -i | grep ini
returns:
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
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?
回答1:
Current versions of Mac OS X do not ship with a php.ini
. PHP uses internal defaults for all settings.
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.
回答2:
Edit: The following method was tested and I confirm it works on macOS, Linux and Windows' CMD and Bash
All you need to type in the terminal/CMD/Bash is
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)
回答3:
There is a PHP function called php_ini_loaded_file() which returns the path of php.ini which is loaded.
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';
}
?>
回答4:
You can use the find
command 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 / -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.
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/
回答5:
php -r "echo php_ini_loaded_file();"
on my machine returns:
/usr/local/etc/php/7.1/php.ini
;)
回答6:
This worked for me in MacOS Sierra with PHP 7.1 installed:
Create a php file called phpinfo_temp.php (remember to remove this file when you're done):
<?php phpinfo(); ?>
Load the file and you'll notice about 7 variables down: "Loaded Configuration File:". This is the php file that is loaded.
Backup the php.ini file before editing:
sudo cp /usr/local/php5/lib/php.ini /usr/local/php5/lib/php.ini.backup
Then edit php.ini
sudo nano /usr/local/php5/lib/php.ini
Once you're done editing, restart the apache server
sudo apachectl restart
回答7:
most often the .ini
file doesn't exist as is, but it is named .ini.default
in the /etc
.
回答8:
I'll add an updated answer for anyone dealing with this on MacOS Mojave and PHP 7.1
Running php --ini
in the terminal returned this:
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.default
file in /private/etc/
, duplicated it and renamed it to php.ini
, which now gets loaded properly:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
来源:https://stackoverflow.com/questions/40515949/where-are-ini-files-on-macosx-sierra