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.<
Here is the complete method to modify correct php.ini
in mac.
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
php.ini
via sudo vi /usr/local/etc/php/7.4/php.ini
:wq
sudo apachectl restart
You are changes should be now reflected, if done correctly :)
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
You should find it in /private/etc if it exists, otherwise:
sudo cp /private/etc/php.ini.default /private/etc/php.ini
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.
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.
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();