16

Simple question: where is the correct PHP.INI location in Mac OSX El Capitan?

I tried to update the one in /etc folder, but nothing changed.

Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78
delphirules
  • 6,443
  • 17
  • 59
  • 108

6 Answers6

20

The default location on OSX El Capitan and macOS Sierra is /etc/php.ini

But if that file doesn't exist, php will use /etc/php.ini.default. Don't forget to create a copy if you want to make changes:

$ sudo cp /etc/php.ini.default /etc/php.ini   

Also, php will scan /Library/Server/Web/Config/php dir for additional .ini files

Restart Apache if you made any changes:

$ sudo apachectl -k restart  

Note: if you install PHP7, this location will change to /usr/local/etc/php/7.0/php.ini

Simon Backx
  • 1,282
  • 14
  • 16
  • Cheers! - this gem seems lost amongst a lot ofther SO advice that didn't work for me.... – n99 Sep 09 '16 at 16:21
19

i know three ways:

  1. php -i | grep php.ini
  2. php --ini
  3. create php file with following line: <?php phpinfo(); and open the file in the browser
Jirson Tavera
  • 1,303
  • 14
  • 18
5

Simple solution

  1. create php info file in your web folder

    <?php
    
     // Show all information, defaults to INFO_ALL
    phpinfo();
    
    ?>
    
  2. open the file in browser

  3. look for

INFO_GENERAL 1 The configuration line, php.ini location, build date, Web Server, System and more.

Taken from php manual


Another option is to use

<? php_ini_loaded_file(); ?>
davejal
  • 6,009
  • 10
  • 39
  • 82
3

Strange thing that phpinfo() does not display the file location, but here it is: /etc/php.ini.default

gonza
  • 61
  • 3
  • 2
    It's actually possible that PHP is running without a php.ini file and is just running off defaults. If you copy /etc/php.ini.default to /etc/php.ini and restart Apache it will display /etc/php.ini as the Loaded Configuration File. – AndyDunn May 24 '16 at 21:11
1
ob_start();
phpinfo();
$output = ob_get_clean();
preg_match("/(Loaded Configuration File => )([\/\w.]+\.ini)/i", $output, $matches);

echo $matches[2];  

In my case I got:

/opt/homebrew/etc/php/8.1/php.ini

devope
  • 127
  • 11
0

This is a polished version of "Simple solution", someone posted before

  1. create php info file in your web folder
  2. <?php phpinfo();?>
  3. open the file in browser
  4. look for php.ini
Justin Hammond
  • 595
  • 8
  • 20
Zia
  • 9
  • 2