PHP error logs with MacPorts on OSX

I’ve recently had to switch laptops while my main machine is in for repair (again), and this has reminded me of an issue I seem to encounter with MacPorts PHP. I make extensive use of the PHP function error_log during development, to track variables and ensure that things within the code are as I expect.

Maybe it’s me, but MacPorts PHP seems to have an issue writing to an error log unless you do some quick configuration. So, as this blog is meant to function partly as my outboard brain, here’s what I had to do. (Some of this gleaned from patient advice given by Ryan, the MacPorts PHP maintainer, on a misguided bug report I filed.)

First edit your php.ini file, which will probably be at /opt/local/etc/php.ini with your favourite text editor. Scroll down until you get to the line saying ;error_log = filename. I changed this to error_log = /Users/simon/Library/Logs/php.log (you’ll need to substitute “simon” with your own username, or choose somewhere else for it to go.

Then you need to make sure that Apache/PHP can write to the error log location you’ve just specified, I did this by running the following in Terminal:

$ sudo chmod 755 ~/Library/
$ sudo chmod 755 ~/Library/Logs
$ sudo touch ~/Library/Logs/php.log
$ sudo chmod 777 ~/Library/Logs/php.log

Then restart your Apache, probably something like:

apache2ctl restart

After those steps I was able to use the Console app to view my logs, and make web development that little bit easier.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.