HowTo: Create a local environment using MAMP

Last updated on
27 December 2023

It is generally recommended to use a Docker-based solution, such as DDEV or Lando, for local Drupal development, rather than manually installing MAMP.

MAMP creates a local server environment on Mac OS X by installing PHP, MySQL, and Apache right out of the box. This will make Drupal much easier to install because the components don't have to be installed separately. This page is to be used in conjunction with the installation instructions for Drupal on Mac OS X.

Also you may want to check out this video in the Videocasts section of the handbook: Installing a Local Web Server on Mac OS X.

Download MAMP

(This will install Apache, MySQL, and PHP in one step.)
Find the latest version here: http://www.mamp.info/
Download and proceed through the installer to install MAMP. Open MAMP and click "start servers," then "Open start page."

Download Drupal

Find the latest Drupal release here: http://drupal.org/.

Move the directory containing the Drupal files into the MAMP htdocs directory:

mv drupal-x.x.x/* drupal-x.x.x/.htaccess /Applications/MAMP/htdocs/yourdrupaldir

where yourdrupaldir is whatever you want the directory to be called.

Note: if you use Finder you may miss moving the .htaccess file which is necessary for clean URLs to work. It is generally best to download and unzip Drupal directly in the document root (default is htdocs) so you don't miss the .htaccess.

Create the Drupal database

To create a database for Drupal

  1. Go to the MAMP start page.
  2. Under "Tools", click the link to "phpMyAdmin".
  3. On the phpMyAdmin page, click the "Databases" tab.
  4. Under the "Create database" section, enter a name for your Drupal database in the "Database name" field.
  5. Select "utf8_general_ci" from the "Collation" drop-down (must be utf8!).
  6. Click "Create".
  7. Look on the left-hand column under the phpMyAdmin logo and make sure that your new database is selected. If it's not, go ahead and click on it.
  8. Select the "Privileges" tab.
  9. Under the "New" section, click on "Add user account".
  10. Fill out the "Login Information" form, making sure to change the "Host" field to "Local". Leaving it as "Any host" will not allow Drupal to connect to your local database and you'll get an error.
  11. Leave the default settings for the remaining sections.
  12. Click the "Go" button. This creates the user and takes you to the "Edit Privileges" for this new user on the new database.
  13. Under the "Database-specific privileges" section, make sure the following check boxes are selected: SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX.
  14. Click the "Go" button.
  15. Click the small home icon under the phpMyAdmin logo in the left-hand column.
  16. Click into the "User accounts" tab.
  17. Next to your new User name, click the "Edit privileges" link. This will take you to the Global settings for this user.
  18. Under the "Data" section, make sure SELECT, INSERT, UPDATE, and DELETE are selected.
  19. Under the "Structure" section, make sure CREATE, INDEX, and DROP are selected.
  20. Click the "Go" button.

You can also use a GUI such as Sequel Pro, just remember to use this as your Socket:

/Applications/MAMP/tmp/mysql/mysql.sock

Changing your password

The default username/password for your MySQL install is now root/root! For security purposes, it's always best to change this. If you're connected to the internet, this is a must.

When you are changing the default user/password from root/root, you need to do two things. Only the first is documented in the MAMP start page FAQ, but if you don't do the second then you get an error message when you try to access anything from the MAMP start page.

  1. Use command line to change the password (as documented in the MAMP start page FAQ)

    Open the terminal and type the following:
    /Applications/MAMP/Library/bin/mysqladmin -u root -p password [NEWPASSWORD]

    It will ask for the current password after you hit enter. Once you have entered that, the MySQL password is changed.

  2. Open a text editor and change the password in the four following files:
    • /Applications/MAMP/bin/phpMyAdmin-X.X.X/config.inc.php

      Find the line that reads...
      $cfg['Servers'][$i]['password'] = 'root';
      ...and change the value 'root' to your new password, retaining the quotes.

    • /Applications/MAMP/bin/mamp/index.php

      Find the line that reads...
      $link = @mysql_connect(':/Applications/MAMP/tmp/mysql/mysql.sock', 'root', 'root');
      ...and change the last parameter to your new password.

      NOTE: You might not have the line above in your file. If you have...
      my $password = '<?php echo $cfg['Servers'][1]['password']; ?>';
      ....you should be fine.

    • /Applications/MAMP/bin/stopMysql.sh

      Find -proot and replace just the root part with your new password. Note that it's important not to have a space between -p and the password itself. For example, change....
      -u root -proot
      ...to...
      -u root -pyourpassword
      If you don't change this you can have zombie mysqld's running after you thought you stopped the server.

    • /Applications/MAMP/bin/checkMysql.sh

      As above, replace -proot with -pyourpassword. If you see an error pop up when you run the MAMP app that says "Error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect", this should fix it.

Or in Mamp Pro you can change the MySQL password under the "MySQL" tab.

Optional: Adjust PHP's memory limit for scripts

NOTE: As of 3/15/2018 the default memory limit is set to 128MB. However, you may want to go through these instructions to check.

By default, MAMP has the memory limit that a script can use set at 8MB, which is the PHP default. Looking at PHP's php.ini-recommended file, this memory limit is normally set at 128MB. To adjust this amount, open the php.ini file in a text editor and change the following line (approximately on line 232):

memory_limit = 8M ; Maximum amount of memory a script may consume (8MB)

PHP.ini file locations:

  • /Applications/MAMP/conf/php4/php.ini
  • /Applications/MAMP/conf/php5/php.ini

In MAMP PRO, don't alter the file directly since it will be recreated at each server start. Please edit the appropriate template (menu File > Edit template > ...) instead.

MySQL issues

Even with larger PHP memory limits you can get timeout errors trying to import large Drupal databases into MySQL. These issues are discussed at length elsewhere with regards to the cache and views cache. Generally the solution is to empty the Drupal cache before importing/exporting databases to/from MySQL.

You may also need to adjust MAMP's memory settings for MySQL. For example, if you get an error message that says, "General error: 2006 MySQL server has gone away," it probably means that you need to increase MySQL's max_allowed_packet setting. To change this setting, edit file /Applications/MAMP/bin/startMysql.sh by appending --max_allowed_packet=100M at the end before the & character.

To adjust MAMP Pro's memory settings navigate to:

File > Edit template > MySQL my.cnf

In the text file that opens, change the value for 'max_allowed_packet' to 100M. Note you can set this in MAMP by adding your own my.cnf file manually.

Adding mysqldump and other libraries to $PATH

In order to make use of mysqldump and other libraries that ship with MAMP you'll likely want to add the location of these libraries to your $PATH (especially if you want to use some of the SQL functions of Drush). Tap the following line into Terminal and hit Return:

export PATH=/Applications/MAMP/Library/bin/:$PATH

Start configuring Drupal!

  • Navigate to http://localhost:8888/yourdrupaldir/install.php
  • Fill in the installation fields using the information provided on the MAMP start page and the database you created in step 4 as well as the username you specified in step 10.
  • Continue filling out the remaining fields during the installation.
  • Refer to the INSTALL.txt, in the Drupal Root directory, for additional help.

NOTE!! If you changed your MySQL username and password, at any time post-installation, you will need to modify that in your local Drupal settings.php file as well.

Adjust the terminal shell path

By default, Mac OS X terminal shell won't find the php binary you're using under MAMP. That is, if you type which php it will tell you /usr/bin/php. This is not the MAMP PHP binary.

To solve this, find the PHP binary used by MAMP. It will look something like this: /Applications/MAMP/bin/php/php5.5.10/bin/php

You can then add this path to your ~/.profile or ~/.bashrc file, so it looks like this:

export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH

Then restart the terminal or type source ~/.profile. Then typing which php will show you MAMP's PHP binary.

Note that if you switch PHP versions using the MAMP user interface, this will not change the path being discovered by the shell. You'll have to edit ~/.profile to point to the new binary in order to do this.

Temporary Files Note:

By default the File System settings (admin/config/media/file-system) will place the temporary files directory inside /Applications/MAMP/tmp/php which should be changed to something like files/tmp or sites/files/tmp to avoid later confusion.

Clean up your Localhost URL

If you would like to shorten your URL from "http://localhost:8888" to "http://localhost" follow these instructions:

  • Open the MAMP application
  • Click on "Preferences" and then "Ports"
  • Change the Apache Port to 80 (the standard web server port)

In MAMP PRO, change the port of apache to 80 and click on apply.

Help improve this page

Page status: No known problems

You can: