Quick Command-Line Tips For Local Drupal Development With MAMP

In preparation for heading off to DrupalCon Paris, I decided to update my local development stack, bite the bullet, and try out the MAMP project. I've resisted this for a while because it's different than a normal *nix environment in that it uses odd port numbers and some other oddball configuration patterns, and because I'm inherently distrustful of "all in one" installers.

Nevertheless, I realized this morning that I didn't have time to re-roll my usual development package, compile GD, and install/update PHP, MySQL and Apache over the somewhat crippled software that comes with MacOS standard. I'm also looking forward to enhancing our development infrastructure here at Chapter Three to better support local/offline work -- as we've expanded from three to five to more than ten active developers, making this an option offers increasing value to our central development server. It's generally fast (no load issues or upload lag) and you can take it with you on a trans-Atlantic 747.

Anyway, once you get the lay of the land a lot of configuration is pretty intuitive, and since it appears that there aren't many MAMP posts explaining the package from the perspective of low-level development tools, I thought it might be useful to post some notes from my initial experience. Here are a few quick MAMP tips for those of us used to working with the command-line for Drupal development.

Up The Memory Limit!

First things first: MAMP ships with a very low PHP memory_limit value; far too low for Drupal. The first thing you should do is update the /Applications/MAMP/conf/php.ini to bump the memory_limit from 8mb to something more sane like 64 or even 128mb. You're not going to do performance work on your desktop, so might as well just avoid those annoying "out of memory" errors.

Use Local VirtualHosts

Often it's nice to be able to organize your work into different servers/domains rather than a series of subfolders, and the best way to that as we all know is with Apache VirtualHosts. To use these with MAMP, try the following technique:

  • Edit the /Applications/MAMP/conf/apache/httpd.conf file to uncomment the NameVirtualHost * line at the bottom, and add your own below that says Include vhosts/*
  • Create a new directory: /Applications/MAMP/Library/vhosts
  • Add a line to your /etc/hosts file for the false domain such as 127.0.0.1 organicgroups.local
  • Add a file (in this case I called mine "organicgroups") to the /Applications/MAMP/Library/vhosts directory like so:
    
      ServerName organicgroups.local
    
      DocumentRoot /Users/joshk/Sites/organicgroups
      
        Options FollowSymLinks
        AllowOverride None
      
      
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
      
    
      ErrorLog /Applications/MAMP/logs/organicgroups.error.log
    
    
    
  • Restart MAMP's apache manually by triggering /Applications/MAMP/bin/apache2/bin/apachectl restart. I find this better than stopping/starting in their UI since you'll get useful error messages if you made any mistakes.
  • Load up organicgroups.local:8888 (subbing in your domain of course) and start developing!

Use Command-Line Mysql

While PHPMyAdmin is great for a lot of things, it can be limited in terms of importing large data-sets, and those of us familiar with mysql on the command line may find the web interface cumbersome and unfamiliar.

However, since MAMP runs on a non-standard port and socket, your included command-line client binary can't connect to it by default. I discovered the secret sauce was specifying both port and socket like so:

mysql -u root -p -P 8889 -S /Applications/MAMP/tmp/mysql/mysql.sock

Once I figured that out, I immediately added a .my.cnf file in my MacOS home directory like so:

[client]
user="root"
pass="root"
port=8889
socket="/Applications/MAMP/tmp/mysql/mysql.sock"

Now I can connect to MAMP's mysql server using the old familiar shell client. With this, enough memory for PHP, and dedicated virtualhosts for my development sites, I'm off and running to build great Drupal on the localhost!

Topics