All in the <head>

– Ponderings & code by Drew McLellan –

– Live from The Internets since 2003 –

About

PHP on OS X

26 November 2003

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.

- Drew McLellan

Comments

  1. § zlog: wouldn’t this do the same job?

    sudo vi /path/to/file/php.ini
    Password: *********
  2. § Jesse: In most cases yes but X has some odd permission quirks.

    Hehe.. err.. hahah.. ya the root v admin debate rages with OS X. I had a similar issue back with X.2 when I had someone ask me to configure mySQL for them. Boy did I hate Apple for a day or two.

    I think the idea with admin is so that you can’t totally take out your system files. In theory removing the threat of any virus that will reformat your machine so I am told. But you are like this >
  3. § Drew: Ronan - sudo was the first thing I tried - no joy.

    I understand that on OS X Server the root account isn’t disabled - it’s just a client thing, which makes sense in a way. It’s very unlikely that you’d need the root account if you’re purely using a machine as a client. I guess Apple figure that if you’re doing stuff that needs access to root, then you can cope with working out how to enable it.
  4. § Drew: btw ... I think you made a typo: vi should be emacs ;-)
  5. § Adrian: Personally I get along just fine with sudo. Can’t face learning vi or emacs though :) So I usually just do either:
    sudo pico /path/to/file
    or
    bbedit /path/to/file
    bbedit has some nice tricks up its sleeve with permissions.

    I can’t think of a good reason to enable root in OS X, except to satisfy a habit learned elsewhere :)
  6. § George: Can’t say I would be too happy with any application that had ”some nice tricks up it’s sleeve” when it came to file permissions. I had no problems with sudo although I never needed to use it until after I had downloaded the latest updates.
  7. § Chuck Han:

    php.ini is not necessarily in /usr/local/php/lib—it might not even exist. Assuming you’ve got php running, put the phpinfo.php file somewhere your webserver display it. phpinfo.php has a single line:

    phpinfo(); (enclosed by the php open and close tags)

    It generates a web page that will tell you where the server expects to find php.ini.
    If the file isn’t there, then php is running the default configuration. You should have a file default configuration file—it may be called php.ini.default. You can find the default configuraiton file by using the following command:

    sudo find / -iname ‘php.ini*’

    Once you find that file, just make a copy of it (calling it php.ini, of course) to where the php expects to find it, and then you can start tailoring php the way you want to.

  8. § Dan:

    I have made this change in the php.ini file and checked to make sure PHP is looking in the proper place. Still getting a blank page on every error. Argh. Makes debugging pretty difficult.

Photographs

Work With Me

edgeofmyseat.com logo

At edgeofmyseat.com we build custom content management systems, ecommerce solutions and develop web apps.

Recent Links

Affiliation

  • Web Standards Project
  • Britpack
  • 24 ways

About Drew McLellan

Photo of Drew McLellan

Drew McLellan has been hacking on the web since around 1996 following an unfortunate incident with a margarine tub. Since then he’s spread himself between both front- and back-end development projects, and now is Director and Senior Web Developer at edgeofmyseat.com in Maidenhead, UK (GEO: 51.5217, -0.7177). Prior to this, Drew was a Web Developer for Yahoo!, and before that primarily worked as a technical lead within design and branding agencies for clients such as Nissan, Goodyear Dunlop, Siemens/Bosch, Cadburys, ICI Dulux and Virgin.net. Somewhere along the way, Drew managed to get himself embroiled with Dreamweaver and was made an early Macromedia Evangelist for that product. This lead to book deals, public appearances, fame, glory, and his eventual downfall.

Picking himself up again, Drew is now a strong advocate for best practises, and stood as Group Lead for The Web Standards Project 2006-08. He has had articles published by A List Apart, Adobe, and O’Reilly Media’s XML.com, mostly due to mistaken identity. Drew is a proponent of the lower-case semantic web, and is currently expending energies in the direction of the microformats movement, with particular interests in making parsers an off-the-shelf commodity and developing simple UI conventions. He writes here at all in the head and, with a little help from his friends, at 24 ways.