PHP + MySQL + Apache on OS X Leopard

I use my mac to develop websites, and I’ve had to do some messing around to get my new Leopard 10.5 operating system to be as good a development environment as Tiger was. Here is what I had to do:

MySQL
Turns out that you have to reinstall MySQL on Leopard. Whoops! I guess I lost my old databases when I upgraded. I should figure out a way to have them save in my user folder. Anyway, go here to get the PKG files. The MySQL preference pane is busted and so is Navicat, so I went and got the official MySQL GUI Tools to set everything up again.

PHP
For these next steps it’s helpful to have Textwrangler to edit your system files.

  • Open terminal, and type sudo touch /private/etc/php.ini.
  • Then go to TextWrangler, and File > Open Hidden /private/etc/php.ini.default and copy all.
  • Open /private/etc/php.ini and paste all into there.
  • Remove the semicolon (uncomment) line 625, which should be extension=php_mysql.dll
  • On line 760, make it read mysql.default_socket = /private/tmp/mysql.sock
  • Save and close the file.

Apache
To get PHP working on Apache (ht to SiteCrafting for this):

  • In TextWrangler, open the hidden file /private/etc/apache2/httpd.conf
  • Remove the poundsign (uncomment) line 114 which should be about the php5_module
  • Also I added the following two lines at line 405:
  • AddType application/x-httpd-php .php
  • AddType application/x-httpd-php-source .phps

Also I use Apache virtual hosts so I can develop multiple sites. I keep these sites in my sites folder. If you’re like me, you’ll want to:

  • Still in httpd.conf from above, change the DocumentRoot directory to be “/Users/josh/Sites” (your username instead of Josh, obv)
  • Change the directory at line 190 to match what you put above
  • Save / close
  • Open /private/etc/apache2/extra/httpd-vhosts.conf and add your virtual hosts, then save and close. I use variations of:

DocumentRoot “/Users/josh/Sites/joshreisner.com/www/”
ServerName joshreisner.site
ServerAlias www.joshreisner.site

To get those local addresses working, you can’t use the NetInfo Manager like you could in Tiger. Assuming you have installed the command line tools in TextWrangler > preferences, you can

  • go to terminal and type edit /etc/hosts
  • duplicate the line that says 127.0.0.1 localhost
  • replace localhost with your servername, eg joshreisner.site from above
  • save and close

Finally, I had trouble setting permissions on my Sites directory using Finder (it crashed every time I tried). Here’s what I did, which I don’t advise as a long-term solution because it’s too generous with the permissions:

  • go to terminal and type sudo chmod -R 777 /Users/josh/Sites

Now you can go to System Preferences > Sharing and start web sharing and you should be all set. Good luck!

posted: Saturday 10/27/2007

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>