All in the <head> – Ponderings and code by Drew McLellan –

PHP on OS X

After installing Panther at the weekend, I decided that I really should install PHP and MySQL again so that I can test portability of my PHP. The last time I installed PHP and MySQL on the Mac was back when I was running Cheetah, and I rapidly discovered that the process has changed quite a bit since then. In fact, it’s a whole lot simpler, Jaguar and Panther already have a MySQL user set up on the system by default – so it couldn’t be easier.

Anyway, installation of the entropy.ch package was uneventful and straightforward. I copied the code from my current PHP project over to the Mac (yay for cross-platform network browsing in Panther), set up a virtual host in my httpd.conf, restarted apache (apachectl restart for those taking notes), ran up the project in Safari and … nothing. No page, no error, no output, no message. Blank page.

Okay, so I figured that my code was erroring somewhere right near the top, but that the PHP module had been configured not to throw errors to the screen. No problem I thought – just need to update the php.ini file. Could I find it? Turns out it’s at /usr/local/php/lib/php.ini, and unsurprisingly it’s the top FAQ on the site.

I fire up emacs and comment out the display_errors = Off statement at line 292 of my php.ini. Easy – except the file won’t save, I don’t have permission. I’m the highest level of admin on my own machine and I can’t modify a simple ini file. Looks like I need to be root, except this is OS X client, and root isn’t enabled by default. (This was supposed to just work wasn’t it?).

Here’s how you enable root on OS X. Open up a Finder window and browse to Applications/Utilities, and run NetInfo Manager. From the Security menu, click Enable Root User and just follow your nose (you’ll need to set a password – make it a good one).

I abandon my emacs session, su to root and reopen the file. Make the edit, save the file, exit emacs. Restart apache. Deep breath. Refreshed Safari, and I’ve never been so pleased to see an error message in my life. The error? I forgot to chmod the files to give PHP permission to run them. Oops.