Skip to main content
Menu

How to setup Mac OS X 10.6 Drupal environment

Vesa Palmu 2010-11-03

I've seen a lot of different local development setups on the computers of our own developers and students in our Drupal training. There are also plenty of blog posts, articles and HOWTOs on setting up PHP development environment on Mac. What I haven't yet found is a comprehensive guide on how to set up a clean and productive environment. So I decided to write one on my own. Unfortunately, setting up a clean environment that supports everything Drupal developers need, and does not get in the way of everything, is a bit hairy process. Many people prefer using MAMP, Macports or other methods, but OS X has almost everything you need already built in – and it's not THAT complicated to set the environment up. This post and some upcoming posts will describe what I consider to be an ideal development environment. Comments are definitely welcome.{C}

Prerequisites:

  • OS X 10.6 (will also work for other versions, but you might have to modify some parts)
  • Admin permissions on your Mac
  • Developing on PHP 5.3 & latest MySQL version

Installing MySQL

Your Mac comes with PHP and Apache. You only need to install MySQL & Drupal and do a bit of configuration. Go and get MySQL from their web site.

MySQL download

The community edition for x86, 64-bit as DMG archive is the version you will want to get. Exact MySQL version number is not that important, the most recent one is ok.

Install MySQL

Mount the DMG disk image by double-clicking it and follow the instructions to install MySQL. You will also want to install the prefPane in order to start and stop the database from OS X System Preferences panel and MySQLStartupitem in order to keep MySQL running after reboot. Just hit continue on all screens and type in your password when being asked.

Start MySQL

After the installation, go to OS X System Preferences pane, start MySQL server and check the checkbox to automatically start on startup.

System setup

In order to run Drupal you need to configure your Apache, PHP and a few small things in OS X. It's easiest to do this by starting terminal application from your Applications / Utilities. Let's start by settings some environment variables:



echo "export PATH=\$PATH:/usr/local/mysql/bin" >> ~/.profile

To get the new profile active close the terminal window and open a new one.

You need root permission in order to modify these files. If your Mac account is not an administrator account you can not do this. On the terminal prompt type:



sudo -s

If you're running sudo for the first time, you will get a warning message. Nevermind – you know what you're doing – right? Just type in your password when prompted. Keep this terminal window open for rest of the installation. Start by creating a short name for your local sites:



/Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts &

This enables you to edit your hosts file that has local aliases for IP addresses. Add the following lines to the end of the file:



127.0.0.1 d6
127.0.0.1 d7
127.0.0.1 customer-1
127.0.0.1 customer-2

Save and quit editor. When you want to add additional sites in the future you will need to add more aliases to this file.

You also need one small change in order to make MySQL compatible with OS X PHP settings. Go back into the terminal and run:



mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Configuring Apache

Next, edit Apache settings:



/Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/apache2/httpd.conf &

Edit the following lines in the file by replacing the original with modified version.

Original:



#LoadModule php5_module        libexec/apache2/libphp5.so

Modified:



LoadModule php5_module        libexec/apache2/libphp5.so

Original:




Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all


Modified:




Options All
AllowOverride All
Order deny,allow
Deny from All
Allow from 127.0.0.1


Original:



# User home directories
Include /private/etc/apache2/extra/httpd-userdir.conf

Modified



# User home directories
#Include /private/etc/apache2/extra/httpd-userdir.conf

Original:



# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf

Modified



# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

Original:



# Various default settings
#Include /private/etc/apache2/extra/httpd-default.conf

Modified:



# Various default settings
Include /private/etc/apache2/extra/httpd-default.conf

Save the file and close TextEdit. You also need to modify the virtual hosts, so it's back to the shell again:



/Applications/TextEdit.app/Contents/MacOS/TextEdit \
/etc/apache2/extra/httpd-vhosts.conf &

Original:




    ServerAdmin

DocumentRoot "/usr/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common



ServerAdmin

DocumentRoot "/usr/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common


Modified:




DocumentRoot "/Users/mearrafinland/Sites/drupal-6"
ServerName d6



DocumentRoot "/Users/mearrafinland/Sites/drupal-7"
ServerName d7



DocumentRoot "/Users/mearrafinland/Sites/customer"
ServerName customer-1
ServerAlias customer-2


In this you need to replace "mearrafinland" with your own user account. Save the file and close TextEdit.

The last thing you need to modify in Apache is the number of simultaneous processes. Since this is a single user environment we don't have to serve many users at the same time. Back to the shell:



/Applications/TextEdit.app/Contents/MacOS/TextEdit \
/etc/apache2/extra/httpd-mpm.conf &

Again edit the file:

Original:




StartServers          1
MinSpareServers       1
MaxSpareServers      10
MaxClients          150
MaxRequestsPerChild   0


Modified:




StartServers          1
MinSpareServers       1
MaxSpareServers       2
MaxClients           10
MaxRequestsPerChild 100


Save the file and close. This will make sure Apache will not use too much resources and it can be left running on background on any modern Apple computer. Now we are ready to start Apache

Sharing preferences

Go to System Preferences / Sharing and enable web sharing.

Installing Drupal

You still need to install Drupal. To make life easier, let's start by installing Drush. Go to http://drupal.org/project/drush and download the latest recommended release. After download double click the drush package to extract it. Let's install it for system wide use, so it's back to the shell again:



mv ~/Downloads/drush /usr/local/
ln -s /usr/local/drush/drush /usr/bin/drush

After this you can continue by downloading Drupal 6 and 7:



cd ~/Sites/

drush dl drupal-7.x
mv drupal-7.x-dev drupal-7
mkdir drupal-7/sites/default/files
cp drupal-7/sites/default/default.settings.php \
drupal-7/sites/default/settings.php
chmod o+w drupal-7/sites/default/settings.php \
drupal-7/sites/default/files

drush dl
mv drupal-6.19 drupal-6
mkdir drupal-6/sites/default/files
cp drupal-6/sites/default/default.settings.php \
drupal-6/sites/default/settings.php
chmod o+w drupal-6/sites/default/settings.php \
drupal-6/sites/default/files

ln -s drupal-7 customer
chown -R mearrafinland:staff drupal*

Create databases to both sites:



mysql -uroot -e "create database drupal6;create database drupal7;"

Again remember to replace mearrafinland with your own user account. You need to chown the directories if you were running these instructions as root (which you were if you haven't closed your console).

And now we are finally ready to install Drupal. Point your browser first to http://d7/ and follow the normal Drupal installer. Database names are drupal6 and drupal7 and addresses simply d6 and d7. Database username for both sites is root and you may leave password blank. Please note that leaving password blank is NOT a good idea in any production environment, but since this is a local development environment it's safe and convenient to do so.

After you have installed both Drupal 6 and 7 it's time to make sure they don't complain about permissions of settings.php. One more trip to the shell:



chmod o-w ~/Sites/drupal-6/sites/default/settings.php \
~/Sites/drupal-7/sites/default/settings.php

You can now close the terminal.

That's it!

You've installed a clean and functional Drupal environment on your Mac with minimal software installations. Some modules on Drupal 6 will still give you warnings or even problems since you are running PHP 5.3, but for many developers this is not an issue. This is also not an issue with Drupal 7.

Please note that now you can also access your Drupal 7 with http://customer-1/ and http://customer-2/ urls. These can be used to set up Drupal multisite setup quickly. It's also easy to add additional local names for different projects either using multisite or installations to separate directories.

I will follow up on this blog post on how to set up PHP extensions (APC, uploadprogress & friends), debug environment, better notifications and other small tweaks that boost developer productivity. We have also set up Aegir on OS X and will blog about that in the future.