Drupal 6 on OS X 10.6

Running Drupal on OS X 10.5 was a pretty huge pain in the ass. It's much easier in in 10.6 since it includes PHP 5.3 with GD and the PDO out of the box. And Drupal 6.14 resolves the PHP 5.3 incompatibilities.

In this guide I'll walk through the process I used for reinstalling OS X, then installing MacPorts and using it to install MySQL.

Note: I've shortened this up a bunch since it was first posted (originally it was using PHP 5.2 from MacPorts). I also want to make it clear that I am familiar with MAMP but would rather punch myself myself in the face than use it. If you'd like to go right ahead since it's probably easier, and as evidenced by the commenters below, you're in good company. But I'm going to continue to compile my own so I know where everything ends up.

A Note for Those Upgrading From 10.5

One thing to note before we start. These instructions assume a clean installation. Apple doesn't come right out and say it but the $29 10.6 disc can be used for new installations or upgrades.

If you followed my previous guides for compiling PHP and Apache I'd recommend the following upgrade procedure. I want to be very clear that this worked fine for me on two computers but I won't take any responsibility if it doesn't work as well for you. Consider yourself warned.

  1. Use something like SuperDuper to make a bootable back up of your system to an external drive.
  2. Boot off the external drive (holding down the option key will let you choose the boot volume) and ensure that everything works correctly.
  3. Unplug your backup drive.
  4. Insert the OS X DVD and boot into the installer.
  5. Use the Disk Utility to erase your computer's hard drive.
  6. Install OS X
  7. After the reboot re-attach your hard drive and use the Migration Assistant to restore your Users, Applications and Settings but uncheck the Other files and folders option.
  8. Manually move any of the other files which may include MySQL databases in /opt/local/var/db/mysql5/.

At this point you should have a clean installation with the majority of your data migrated. I'd suggest keeping the backup drive around for a while incase you find that you've missed something.

Install XCode

Install the XCode package from Optional Installs directory on the install DVD.

Install MacPorts

Follow the directions to install Mac Ports.

Become root

To follow these instructions you need to be running as the root user using the default sh shell. If you've got administrator permissions you can open up a Terminal window and switch users using the sudo command then provide your password.

amorton@minivac:~% sudo su
Password:
sh-3.2#

Install MySQL

Use port to install MySQL:

port install mysql5-server

You'll need to create the databases:

/opt/local/lib/mysql5/bin/mysql_install_db --user=mysql

Let launchd know it should start MySQL at startup.

launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

Start MySQL:

/opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper restart

Create a symlink for the mysql5 executable so it can be invoked as mysql (the way that the mysql_secure_installation script expects it to be named):

ln -s /opt/local/bin/mysql5 /opt/local/bin/mysql

Secure the server and set a new admin password:

/opt/local/lib/mysql5/bin/mysql_secure_installation

Create a configuration file:

cp /opt/local/share/mysql5/mysql/my-large.cnf /etc/my.cnf

Edit /etc/my.cnf using your editor of choice and make the following changes to the [mysqld]:

  • Change the maximum packet size to 16M:
    max_allowed_packet = 16M
  • Enable network access by uncommenting the first line but limit access to the localhost with the second line:
    skip-networking
    bind-address = 127.0.0.1

Restart MySQL to have the settings changes take effect:

/opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper restart

PHP

You need to create a php.ini file:

if ( ! test -e /private/etc/php.ini ) ; then cp /private/etc/php.ini.default /private/etc/php.ini; fi

Now open /private/etc/php.ini and set the correct location for MySQL's socket by finding:

mysqli.default_socket = /var/mysql/mysql.sock

And changing it to:

mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock

Repeat for both mysql.default_socket and pdo_mysql.default_socket.

Enable PHP by opening /private/etc/apache2/httpd.conf in the editor of your choice and making the following changes.

  • Uncomment this line:
    #LoadModule php5_module        libexec/apache2/libphp5.so
  • Find and change this one:
        DirectoryIndex index.html

    To this:

        DirectoryIndex index.php index.html

Then restart Apache:

apachectl graceful

XDebug

Totally optional steps here.

Use pecl to install XDebug.

pecl install xdebug

You'll need to edit your /etc/php.ini (you'll need to copy one of the sample .ini files) and add the following line:

zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

My VirtualHost Setup

I like being able to have multiple Drupal sites a few keystrokes away so I create virtual hosts for d5, d6 and d7 using the following procedure.

Edit /etc/apache2/users/amorton.conf and add a VirtualHost to the Apache config:

# This should really be in httpd.conf but i'm keeping it simple by doing it here:
NameVirtualHost *:80

<VirtualHost *:80>
    ServerName d6
    DocumentRoot /Users/amorton/Sites/d6
    <Directory /Users/amorton/Sites/d6>
        AllowOverride All
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName d7
    DocumentRoot /Users/amorton/Sites/d7
    <Directory /Users/amorton/Sites/d7>
        AllowOverride All
    </Directory>
</VirtualHost>

Obviously you'd want to replace amorton with your username.

Add an entry to the /private/etc/hosts file:

127.0.0.1       d7

Thanks Drewish

Really appreciate this post. Had to do a quick install of MacPorts on a loaner computer this weekend. Much easier following these instructions than it was the first time I set this up on 10.5.

-sean

For some reason on my system

For some reason on my system when I used /opt/local/bin/pecl it found the phpize from /usr/bin/phpize which in turn caused xdebug (or any other extension) to be built for PHP5.3 and to be installed into /usr/lib/php/extensions/no-debug-non-zts-20090626/. I got around this, and the command line issue by renaming php from /usr/bin to php53 and phpize53 (an easily removable modification).

Mysql in Snow Leopard

Mysql in Snow Leopard would be the appropriate title ;-)

but in case you didn't know, you can download a compiled package
http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg

Joachim

Good point

Yeah, I used to use those but they aren't as easy to upgrade as the MacPorts versions.

XAMPP

XAMPP makes this all incredibly easy. Can't recommend it enough.

If you're only looking for

If you're only looking for local development (and not putting up a server for the outside world) then it's very easy to run Drupal on Mac OS X using either MAMP och XAMPP. I didn't even now that "Running Drupal on OS X 10.5 was a pretty huge pain in the ass." since it was very easy with MAMP.

Another reason to use MAMP is that no released version of Drupal 6 is compatible with PHP 5.3 and 10.6 ships with 5.3. So even if you get it up an running on 10.6 you're going to have problems with Drupal 6.

From what I've read a lot of

From what I've read a lot of the *AMPs have upgraded to PHP 5.3 so you need to check their version numbers as well. I haven't quite decided if I'm going to go the MacPorts PHP route or just work tweaking the error reporting in php.ini but there will be some updates to this post shortly.

This is what's included in

This is what's included in MAMP 1.8.2 (2009-09-08):
- Apache 2.0.63
- MySQL 5.1.37
- PHP 4.4.9 & 5.2.10