Setting up a Mac development environment

Submitted by Erik on Sun, 05/29/2011 - 23:46

There are many ways to get Drupal running on your Mac. OS X comes preinstalled with PHP and Apache, so theoretically, you'd only need MySQL. Acquia makes a separate version that includes Drupal, Apache, MySQL, and PHP (aka DAMP) already set up. This version is great if you really want to get up and running quickly. It's tied to the Acquia distribution of Drupal which has some extra features that we don't tend to use for our development.

What I've found a reasonable compromise has been to use MAMP (a Mac application that provides - Apache, MySQL, PHP) and customize my own Drupal installation. This allows me to approximate our dev/production systems reasonably closely.

Download MAMP

http://mamp.info/downloads/releases/MAMP_PRO.dmg.zip
You don't need the PRO version, but the way MAMP works is to download this one and then not choose the PRO setup. Once installed, I make the following changes to the system right away:

In the preferences:

  • Start and stop the applications on open/quit

  • don't have MAMP "Open the start page at startup"
  • set Apache to port 80
  • set PHP to 5.2.16 (or whatever matches current dev/prod php)
  • set Apache doc root to /Users/yourusername/Sites/ (mine is set to "/Users/erikp/Sites/")

When setting Apache to port 80, you'll need to provide an admin user/password to use a port below 1024, but it's worth it not to have to add :8888 to all of your URLs.

I, personally, chose not to open the MAMP start page because I'm not using the MAMP version of PHPMyAdmin, so there are no MAMP UI tools that I use. I use Sequel Pro to manage all of my MySQL servers and databases.

Now you should be able to visit http://localhost and see the Apple "Your website" page which is from /Users/yourusername/Sites/index.html

To be able to run mysql and mysqladmin from the command-line without having to specify their full paths within the Applications/MAMP directory, open the .bash_profile file in your home directory. If you don't have a .bash_profile, you can open TextEdit and paste the following into the window and then saving as .bash_profile. If you do have a .bash_profile and need to open it in TextEdit, try opening Terminal from the Utilities folder and typing open -a TextEdit ~/.bash_profile

Once the file is open, you should copy in the following:

export PATH=/Applications/MAMP/bin/php5.2/bin:/Applications/MAMP/Library/bin:$PATH

This will allow you to run Drush commands which need command line PHP and mysql applications which are in /Applications/MAMP/Library/bin/. We'll be editing the .bash_profile again, so remember how to get to it.

Download Drush

The current version can always be found at http://drupal.org/project/drush
You don't need to get a Drupal core version specific, the latest Drush will always work with all Drupal versions.

Unpack it. Move the unpacked drush directory either somewhere in your $PATH or add it to your $PATH. I moved drush into ~/.drush

tar xfz drush-7.x-4.4.tar.gz;
mv drush ~/.drush

Then add the following line to your .bash_profile:

alias drush='$HOME/.drush/drush';

When you modify .bash_profile, you either need to logout and then back in again to take advantage of the changes or you can type the following on a Terminal command line:

source ~/.bash_profile

Now you should be able to type the command "drush" and get something akin to the following (probably with a lot more stuff):

$ ./drush
Execute a drush command. Run `drush help [command]` to view command-specific help.  Run `drush topic` to read even more
documentation.

Global options (see `drush topic core-global-options` for the full list):
-r <path>, --root=<path>                  Drupal root directory to use (default: current directory)            
-l http://example.com,                    URI of the drupal site to use (only needed in multisite environments)
--uri=http://example.com                                                                                       
...

Download Drupal

So great, drush works, now we need to use it to get a copy of the Drupal code.

cd ~/Sites
drush dl drupal

Now, you should be able to call up the webpage: http://localhost/drupal to start the install process.

One of the first stumbling blocks will be that you need to create a settings.php file. Drupal doesn't do this for you.

cd ~/Sites/drupal/sites/default
cp default.settings.php settings.php

The second thing will be to create a database to hold our new site. Since we added /Applications/MAMP/Library/bin to our $PATH, we can call "mysqladmin" directly.

mysqladmin -u root -p create drupal_default

This will prompt you for your root MySQL password, which by default in MAMP is "root".

Now return to the Drupal installer UI on your website and put in:

Database name: drupal_default
Database username: root
Database password: root (unless you changed it ;-)

Let the process run and you're on your way to having a local Drupal installation.

Next up: Repeating the process to run multiple sites easily.

Comments

Add new comment

The content of this field is kept private and will not be shown publicly.

Filtered HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <img src alt height width> <pre>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.