314

I wanted to run some PHP right on my Mac, uncommented httpd.conf, activated web sharing, installed MySQL etc. I can't seem to find my PHP files, most importantly, PHP.ini.

On my old machine it was located in /usr/local/php5/lib But php5 directory doesn't exist in /usr/local..

Do I need to get a package or am I looking in the incorrect place?

Running OS X 10.7.3, PHP 5.3.8, Apache/2.2.21

Thibault Walterspieler
  • 2,272
  • 2
  • 15
  • 25
Orun
  • 4,383
  • 3
  • 26
  • 44
  • 11
    Or `locate php.ini` – Pekka Feb 18 '12 at 17:03
  • 17
    @ralfe It should be added that you need to look for the 'Loaded Configuration File' setting from phpinfo() or `php --ini` (run in terminal window). Because if there is no php.ini both of those will report the Configuration File Path as `/etc` (at least on my OS X 10.8 install). If no configuration file is loaded, then you should try the [answer by mac](http://stackoverflow.com/a/9343210/695671) – Jason S Jul 14 '13 at 02:09
  • /usr/local/php5 is where the php-installer of entropy.ch and liip.ch install(ed) php. It has never been the location of Apples php-installation. – heiglandreas Apr 23 '14 at 05:56
  • 13
    Do this `php -i | grep php.ini` –  Mar 06 '18 at 22:23
  • 1
    on Terminal enter php -r "phpinfo();" – user1502826 Oct 15 '18 at 16:58

13 Answers13

542

To locate the ini file on your machine, open Terminal.app and run the following command:

php --ini

If you need a template for Lion, try this.

vqdave
  • 2,361
  • 1
  • 18
  • 36
rkmax
  • 17,633
  • 23
  • 91
  • 176
  • 2
    I have no loaded php.ini right now. Basically I'm looking for the directory with the "recommended" php.ini template. – Orun Feb 18 '12 at 17:19
413

You should find it in /private/etc if it exists, otherwise:

sudo cp /private/etc/php.ini.default /private/etc/php.ini
mac
  • 5,627
  • 1
  • 18
  • 21
  • Okay, there's a php.ini.default in /private/etc and I'm checking it out. but any idea why don't I have my old php5 folder in usr/local? There used to be a bunch of files in there including a recommended php.ini. Is this a change in a newer version or PHP5 or Lion or something else? – Orun Feb 18 '12 at 17:21
  • PHP5 is included by default in MacOS X since 10.5 with the above location for the php.ini file. If you had installed it manually it should not have been removed during the upgrade to Lion; strange... – mac Feb 18 '12 at 17:26
  • That was on an old machine from quite some time ago (tiger days). This machine is a fresh install. Thanks for the help! – Orun Feb 18 '12 at 17:29
  • 2
    The php.ini.default file on my Lion machine did not match all the default settings when no php.ini was present. Notably short_tags was Off, error_reporting, log_errors, and some minor settings differed. You will want to compare your output of `php -i` before and after creating your php.ini. – spoulson Jan 28 '13 at 04:55
  • 1
    on my mac, I had a file at the /private/etc/php.ini but php seemed to ignore any changes I made there, found it was using the one in /usr/local/php5/lib/php.ini instead – Kit Ramos Jul 19 '15 at 18:48
  • this answer is bad since the location of the php.ini can varies depending on how PHP is installed, OS X version and how the user customises his installation – ericn Oct 12 '15 at 07:29
  • 2
    This answer pointed me to the right direction. cp php.ini.default > php.ini and CLI loaded configuration became /etc/php.ini. Check php -i | grep php.ini after – bpile Jul 23 '18 at 12:00
53

In terminal do php -i | grep php.ini. Should give you some clues ;)

SpoBo
  • 2,100
  • 2
  • 20
  • 28
29

Answers from @Cronk and @Justin got me close on Mac OS X 10.9 Mavericks. In fact, on my system the /etc/php.ini file was missing completely, and it wasn't until I ran phpinfo() on the web server that I observed there was no configuration file. Copying the file from /etc/php.ini.default and adding the fully qualified path to the mcrypt.so library to the config file solved the problem:

cp /etc/php.ini.default /etc/php.ini

Then in /etc/php.ini add the following line (using the correct path to your mcrypt.so file):

extension="/usr/local/Cellar/php54-mcrypt/5.4.29/mcrypt.so"

Then restart Apache2:

apachectl restart
Peter Gluck
  • 8,168
  • 1
  • 38
  • 37
27

As pointed out, the php --ini command will tell you where PHP is expecting to find the php.ini file.

For a standard installation, it's likely to be looking for /etc/php.ini

If you've used macports then PHP may be looking for /opt/local/etc/php5/php.ini

Joat
  • 271
  • 3
  • 2
25

Run phpinfo() from any file and it tells you where it is. Here is a screenshot.

enter image description here

Robert
  • 10,126
  • 19
  • 78
  • 130
  • 3
    this is the best way to go, as you might find copies of the php.ini in other "default" folders but this way will tell you the one it's actually using, so that way you avoid the head scratching and frustration that comes when you make a change but php seems to be totally unaware of said change. – Kit Ramos Jul 19 '15 at 18:51
  • You can also open up the php REPL in your shell by running `php -a` where you then run `phpinfo();`. – metakermit Feb 23 '18 at 18:15
16

I have more than once instance of PHP running so the other answers did not work for me. This did:

Create a PHP file and open its local url in your browser:

<?php phpinfo(); ?>

The PHP.INI path will be listed close to the top.

Justin
  • 26,443
  • 16
  • 111
  • 128
8

1- Find .ini location path

Open Terminal and run command

php --ini

2- copy this path /usr/local/etc/php/7.4/php.ini and open it by command

nano /usr/local/etc/php/7.4/php.ini

3- Make changes and Quit with the keyboard combination Ctrl+X to exit nano

4- run apachectl restart after finish

Islam Alshnawey
  • 692
  • 10
  • 15
  • this solution works for mac users, because found the pho.ini file is dificult, so whit this solutions i can edit php.ini in my terminal. LIKE – Nivaldo Quiñones Dec 15 '22 at 21:24
3

This is rather old thread, but I would like to add a further clarification.

If you have a system that has multiple PHP installations (like mine did) the results you get from using the command line tools MAY BE different than what is actually used by the web server. If you are interested in what PHP is being used by the web server, only use the information gathered from a web page that uses the 'phpinfo()' function.

For example, on my system the versions reported by the two different methods were:

Command line: 5.3.26

Web: 5.3.13

For the php.ini file path things were different, too:

Command line: /private/etc/php.ini

Web: /long/path/to/the/file/php.ini

You can find all the possible php.ini files using this:

find / -name php.ini 2>&1 | grep -v "denied" | grep -v "directory"

(the '2>&1' and 'grep' elements just restrict the output of the command to useful information, i.e. get rid of error messages)

On my system I found 3 INI files. Because I was interested in what the web server was using I knew that I should use the path returned from the web-page results. I made my changes to the php.ini file that was listed there, restarted apache, and re-ran the web page; the new edits were shown there.

To restart apache:

sudo apachectl -k restart

-- J

Community
  • 1
  • 1
Cronk
  • 453
  • 1
  • 6
  • 16
3

On OSX/MacOS do the following in a Terminal window:

Run php --ini at the prompt by typing it and pressing enter

Reports something like: Configuration File (php.ini) Path: /etc Loaded Configuration File: (none) Scan for additional .ini files in: /Library/Server/Web/Config/php Additional .ini files parsed: (none)

...this is because in /etc there is a file called /etc/php.ini.default as an example and to show it is not in use. You need to copy that file to the name php expects so that you can edit it, like this:

Type:

$  sudo cp /etc/php.ini.default /etc/php.ini       (and enter your password)

...then you will see if you run php --ini again that it now sees your new file:

Typing this: php --ini at the prompt should report this:

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

...now edit /etc/php.ini - you want to make sure the following lines (NOT the same line starting with a semi-colon ';') are exactly as follows: log_errors = On (this will turn the logging engine on)

Then, in this section:

; Log errors to specified file. PHP's default behavior is to leave this value
; empty.
; http://php.net/error-log
; Example:
;error_log = php_errors.log
; Log errors to syslog (Event Log on Windows).
;error_log = syslog

If you want to log to the syslog (or Windows Event Log on Windows) then ;error_log = syslog should become error_log = syslog

However, if as you say, you want to log to a file, you uncomment by removing the leading semi colon to make ;error_log = php_errors.log become error_log = php_errors.log or using a full path to place it where you want.

Good luck

1

I start with the 'Hello World!', once I get that displaying in my browser I throw a phpinfo(); in there and you can see all of the things. Tells you which configurations are loaded, everything.

<?php
   echo 'Hello World!';

   phpinfo();
CenterOrbit
  • 6,446
  • 1
  • 28
  • 34
0

You run php_info() and see line bellow :)

Loaded Configuration File   /Applications/XAMPP/xamppfiles/etc/php.ini
Quy Le
  • 2,354
  • 25
  • 18
0

Here is the complete method to modify correct php.ini in mac.

  • Find out the ini location via php --ini, this will give something like below:
    Configuration File (php.ini) Path: /usr/local/etc/php/7.4
    Loaded Configuration File:         /usr/local/etc/php/7.4/php.ini
    Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
    Additional .ini files parsed:      /usr/local/etc/php/7.4/conf.d/ext-opcache.ini
  • Now open the php.ini via sudo vi /usr/local/etc/php/7.4/php.ini
  • Make your changes and exit it via :wq
  • Run final command sudo apachectl restart

You are changes should be now reflected, if done correctly :)

Imran Zahoor
  • 2,521
  • 1
  • 28
  • 38