Where are ini files on MacOsX Sierra?

五迷三道 提交于 2019-11-30 11:01:47

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.

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)

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

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/

php -r "echo php_ini_loaded_file();"

on my machine returns:

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

;)

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

haz

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!