Using MAMP for local Drupal development on a Mac

Date: Fri Apr 25 2014 MAMP »»»» Mac »»»» Drupal

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
    /Applications/MAMP/htdocs/
    
    </span></li><li>Create a database for Drupal <ul><li>Go to the MAMP start page: <a href="http://localhost:8888/MAMP" title="http://localhost:8888/MAMP">http://localhost:8888/MAMP</a></li><li>Click on phpMyAdmin</li><li>Enter a database name in "Create new database" and click on Create</li></ul></li><li>Adjust the PHP memory limit.  MAMP delivers the PHP configured with an 8 megabyte limit.  In  <span class="geshifilter">
    
    /Applications/MAMP/conf/php4/php.ini
    
    </span> and <span class="geshifilter">
    
    /Applications/MAMP/conf/php5/php.ini
    
    </span> find the line reading <span class="geshifilter">
    
    memory_limit = 8M
    
    </span> and change the 8M to something more reasonable like 64M </li><li>In your web browser visit <a href="http://localhost:8888" title="http://localhost:8888">http://localhost:8888</a> and go through the Drupal installer</li><li>In the installer make sure to enter all the MySQL connection parameters given on <a href="http://localhost:8888/MAMP" title="http://localhost:8888/MAMP">http://localhost:8888/MAMP</a>.  This is 'root' for both user name and password, and MySQL port 8889.</li></ul><p>There are some optional steps you may find helpful.</p><p>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.  </p><ul><li>In the MAMP GUI window click on Preferences, then on the Apache tab</li><li>A text entry box labeled "Document Root" lets you specify whatever path name you like.</li><li>The Select... button opens a file dialog letting you choose a directory for your Document Root</li></ul><p>You may want to try different PHP versions or caching technologies or the Zend Optimizer.  Those are selected in the PHP tab.</p><p>You may want to run Apache or MySQL on different ports than 8888 and 8889.  Those are selected in the Ports window.</p><p>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.</p><ul><li>Duplicate the remote site's files onto your local disk:  rsync --archive <script type="text/javascript">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%75%73%65%72%49%44%40%73%65%72%76%65%72%2e%64%6f%6d%61%69%6e%22%3e%75%73%65%72%49%44%40%73%65%72%76%65%72%2e%64%6f%6d%61%69%6e%3c%2f%61%3e%27%29%3b'))</script>:/path/to/remote/docroot /path/to/local/docroot</li><li>Dump the remote database to a local file:  /Applications/MAMP/Library/bin/mysqldump -u userIDonRemoteMySQL -h hostNameOfRemoteMySQL -p database &gt;data.d</li><li>Create a database in MAMP's MySQL, using the steps above</li><li>Load the data into the database just created: /Applications/MAMP/Library/bin/mysql -u root -p database </li><li>Set $db_url in sites/default/settings.php: $db_url = 'mysql://root:root@127.0.0.1:8889/database';</li><li>Make other changes in sites/default/settings.php</li></ul><p>One things to note is that MAMP bundles command line utilities for MySQL.  They are in <span class="geshifilter">
    
    /Applications/MAMP/Library/bin/
    
    </span> and you can either specify the full path as I've done above, or to add that directory to your PATH.</p><p>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. </p><p>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:  <a href="http://davidherron.com/book-page/4-using-ssh-or-putty-remotely-access-mysql-server">Using SSH or Putty to remotely access a MySQL server</a></p><p></p><!-- google_ad_section_end --><div class="sexybookmarks-default-2030"></div></body></html>