Quick Command-Line Tips For Local Drupal Development With MAMP
Navigation : Back to Blog
Tags :
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 saysInclude 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!
Comments
Post a comment
Presentations
What we've coded
Videos
Upcoming workshops
-
San Francisco, CAJune 3, 2013
-
San Francisco, CAJune 4, 2013 - June 5, 2013
-
San Francisco, CAJune 6, 2013
-
San Francisco, CAJune 7, 2013







Since MAMP is considered dead most Mac users are switching to XAMPP these days.
But XAMPP ships with PHP 5.3 and unfortunately for us Drupal users is Drupal 6 not compatible with PHP 5.3 right now (although they are working on it).
MAMP & MAMP RO are alive! Please check out our blog ... we released some new versions.
Yeah, I just noticed, to my big surprise! That's great news! Everyone, even in the MAMP forums seemed to think MAMP was dead.
And btw, Installing Drush for local Drupal development is a must! It's a fantastic tool that helps tremendously.
Might also be worth taking a look at the Acquia Drupal Stack Installer which has similar components but is already tuned (memory increase etc) to running Drupal. The ability to have it manage virtual hosts, import existing codebases and database dumps seamlessly, in addition to setting up Drupal multi-sites for you as well are all fantastic time-savers.
The features such as importing an existing site or installing a new one work with Drupal 5 - Drupal 7 so it's quite handy. If you're not running MySQL from MySQL.com it's also easy to have it run on the standard port.
DAMP can be found here: http://acquia.com/downloads
Oh and it works on Windows too.
It's easy to change the ports MAMP uses to the typical http and mysql ports. Just open MAMP, click the Preferences button, then the Ports tab.
Having been in the habit of rolling my own development stack for a while, it's great to get updates from those who are more on the cutting edge. :)
Can also be easily done with the Drush command drush sql cli. This will open the mysql shell with Drupal's credentials for you.
Great tips, but I really like using Linux inside a Virtualbox. That could make it easier to configure things like, oh, Varnish and such ;)
Forgot to add the link to the comment http://crackingdrupal.com/blog/greggles/easier-and-safer-drupal-developm...
Feel free to merge this comment into the last ;)
To make things easier, you can add the following line to your .profile file:
export PATH=/Applications/MAMP/bin/php5/bin:/Applications/MAMP/Library/bin:$PATH
This will make all of the MAMP executables default (including mysql, php, and apachectl). Then you don't have to mess with your .my.cnf file, and use cli php with your MAMP php.ini file.
Does anyone have any idea where I can get access to drupal for dummies articles/info? I'm so lost.
Just to add that in the ~90 days since the new "signs of life" MAMP / MAMP Pro posts above, they've rolled out a series of updates, each incorporating new security fixes released by the various underlying Open Source components.
For instance in php, whn using the mysql_connect function, use:
"localhost:/Applications/MAMP/tmp/mysql/mysql.sock"
That way yo can connectto MySQL from your scripts.