sensorario
sensorario

Reputation: 21688

Where are ini files on MacOsX Sierra?

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?

Upvotes: 24

Views: 52590

Answers (8)

Daniel Nitu
Daniel Nitu

Reputation: 435

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)

Upvotes: 2

haz
haz

Reputation: 1

most often the .ini file doesn't exist as is, but it is named .ini.default in the /etc.

Upvotes: 0

Bilal Khoukhi
Bilal Khoukhi

Reputation: 1040

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)

Upvotes: 28

Ulysnep
Ulysnep

Reputation: 405

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

  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

Upvotes: 1

Milan Urukalo
Milan Urukalo

Reputation: 31

php -r "echo php_ini_loaded_file();"

on my machine returns:

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

;)

Upvotes: 2

Paul J
Paul J

Reputation: 1519

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/

Upvotes: 2

user149341
user149341

Reputation:

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.

Upvotes: 55

Samay
Samay

Reputation: 471

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';
}
?>

Upvotes: 5

Related Questions