Using MAMP for local Drupal development on a Mac
MAMP makes it pretty darn simple to do web development on a Mac. While Mac OS X comes bundled with Apache and PHP, MAMP bundles together the latest versions of both along with MySQL. It "installs a local server environment in a matter of seconds on your Mac OS X computer" and is completely self-contained. You can run MAMP alongside the Apache that's built-in to Mac OS X, you can remove MAMP at any time, etc. It's very convenient and flexible.
By default you access the MAMP webserver on non-standard ports. Instead of the default webserver port 80, you access http://localhost:8888/ and likewise the bundled MySQL is on port 8889 rather than whatever the default MySQL port is.
It's pretty simple to get going, however there are a couple small gotcha's to running Drupal within the MAMP setup.
On drupal.org is a couple pages going into setting up a fresh Drupal install within MAMP: Installing Drupal on a local MAMP setup (mac) and HowTo: Create a local environment using MAMP. The steps are to
- Download and install MAMP
- Unpack the Drupal code in
- Create a database for Drupal
- Go to the MAMP start page: http://localhost:8888/MAMP
- Click on phpMyAdmin
- Enter a database name in "Create new database" and click on Create
- Adjust the PHP memory limit. MAMP delivers the PHP configured with an 8 megabyte limit. In
/Applications/MAMP/conf/php5/php.inifind the line reading
memory_limit = 8Mand change the 8M to something more reasonable like 64M
- In your web browser visit http://localhost:8888 and go through the Drupal installer
- In the installer make sure to enter all the MySQL connection parameters given on http://localhost:8888/MAMP. This is 'root' for both user name and password, and MySQL port 8889.
There are some optional steps you may find helpful.
You may want your web files to be in your home directory, and for example to have multiple web directories if you're working on multiple web sites.
- In the MAMP GUI window click on Preferences, then on the Apache tab
- A text entry box labeled "Document Root" lets you specify whatever path name you like.
- The Select... button opens a file dialog letting you choose a directory for your Document Root
You may want to try different PHP versions or caching technologies or the Zend Optimizer. Those are selected in the PHP tab.
You may want to run Apache or MySQL on different ports than 8888 and 8889. Those are selected in the Ports window.
You may want to run an existing Drupal setup on your local machine. For example I keep a local copy of my website so I can hack on the site without bothering the live site. There are several steps that are largely the same as above.
- Duplicate the remote site's files onto your local disk: rsync --archive
- Dump the remote database to a local file: /Applications/MAMP/Library/bin/mysqldump -u userIDonRemoteMySQL -h hostNameOfRemoteMySQL -p database >data.d
- Create a database in MAMP's MySQL, using the steps above
- Load the data into the database just created: /Applications/MAMP/Library/bin/mysql -u root -p database
- Set $db_url in sites/default/settings.php: $db_url = 'mysql://root:firstname.lastname@example.org:8889/database';
- Make other changes in sites/default/settings.php
One things to note is that MAMP bundles command line utilities for MySQL. They are in
/Applications/MAMP/Library/bin/ and you can either specify the full path as I've done above, or to add that directory to your PATH.
Another thing is the $db_url. MAMP delivers it's MySQL with user and password set to 'root' and it's pretty easy to leave that setting alone rather than create another MySQL user. That's configured in the $db_url with the 'root:root' part. I couldn't find in settings.php documentation how to specify the MySQL port. However setting the ':8889' in the $db_url worked.
If the MySQL on your webserver doesn't allow remote MySQL access you may need further tricks. The step above to dump the remote database relies on the local mysqldump being able to access the remote server. One possible trick is to make a tunnel connection to the remote MySQL server as mentioned in: Using SSH or Putty to remotely access a MySQL server