(888) 3 - Drupal
Touch Base

How to Develop Locally with MAMP

Develop Locally MAMP Image

It is often faster and easier to develop a site locally as opposed to remotely. A few of the advantages include not having to worry about server down-time, firewalls or the dreaded edit-save-upload-refresh process.

MAMP is one of the more popular programs for setting up a local development environment on a Mac machine. The acronym ‘MAMP’ stands for the following: Mac, Apache, MySQL, PHP. It includes everything you’ll need to run Drupal locally. A typical operating system for the server environment is Linux for a ‘LAMP’ setup. But in this case, we’re developing locally on a Mac machine and so MAMP is the appropriate setup.

It can be tricky to get Drupal up and running the first time around. We’ll outline the steps below to install Drupal 7 with MAMP to create a local development environment.

1. Install MAMP

The first step is to download MAMP. MAMP and MAMP Pro both come in the zip file. When the download is complete, install MAMP by dragging it into the Applications folder. It’s worth noting that you are welcome to install MAMP Pro for a fee; but you will find MAMP is usually sufficient for most needs. The advantage of MAMP Pro is a better user interface and some advanced features.

After the installation finishes, unmount the disk image. Then, find the MAMP.app inside the Applications folder and double click to open it. Your local server is now running.
You’ll notice there are four tabs. Let’s take a quick look at the preferences:

• “Start/Stop” provides you with the ability to start and stop servers with MAMP either automatically or manually; it also allows you to set a default start page. You will want to later change the default start page to the Drupal directory.
• “Ports” allows you to change the ports for Apache and MySQL. The default ports are probably perfect for your needs; they shouldn’t interfere with other programs but they will require the port to be included in the url (localhost:8888/ instead of localhost/).
• On the “PHP” tab you have the ability to change the running version of PHP. But you shouldn’t need to make any changes here and can keep the default version running.
• The “Apache” tab is where you change the web directory. The web directory is where Apache finds the the website files to host. You may change the name of the folder if you wish. It may be easier to access if you change it to something like “/Users/[name]/Sites” instead of the default “/Applications/MAMP/htdocs”

2. Prepare the Database

Before you attempt to setup the database, verify your servers are running on the main MAMP application screen. Then proceed with the following steps:

1. Open the start page through the button on the main MAMP application screen.
2. Navigate to the “phpMyAdmin” page. Go to the “Databases” menu item. Enter a name into the “Create a database” text field. Make sure the dropdowns are set to “Collation” and “utf8_general_ci” before clicking the “Create” button. Remember the name of your new database, you’ll need it for the Drupal installation.
3. Next you need to set up a MySQL user with permissions for this database. Navigate to the “Privileges” menu at the top of the screen. Click “Add a new user” at the bottom. Enter a username. Select “Local” for the host and set and confirm the password. You can leave the “Grant all privileges on database [database_name]” option selected; or, to be more secure, you may change it to “None” and check the options below: SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, and ALTER. Finally, click the “Go” button. Keep a record of this username and password as you will need them for the Drupal installation.

3. Adjust the PHP Memory Limit

You’ll need sufficient memory to host the Drupal site locally. Drupal 7 recommends at least 60 MB. If you’re developing a social networking site or creating intensive Views, more may be needed. I recommend 128 MB of memory.

To adjust the PHP memory limit, take the following quick steps:
1. Go to the /Applications/mamp/conf/php5 folder.
2. Edit the php.ini file through finding the line that says “memory_limit = 8M” and changing it to “memory_limit = 128M”.
3. Save and close the file.

This will reduce your chances of seeing the white screen of death; which is usually produced when PHP runs out of memory.

4. Install Drupal 7

Download the Drupal core directory from here. Unzip it and place it into the folder in your MAMP “default start page” directory. You can unzip it to your desktop and copy the folder. It’s critical to verify the .htaccess file is copied or Drupal will not work properly. Rename this folder to anything you like; “drupal” is easy to remember. For the following instructions, we’ll use [base] to indicate the folder where the Drupal directory is located.

Inside the “[base]/sites/all” directory, you’ll need to create two folders: “modules” and “themes”. Inside the “[base]/sites/default” folder, you’ll need to create a “files” folder and set the permissions to read/write for everyone. You’ll also need to create a black PHP file called “settings.php”.

Open your web browser and point it to your new site, localhost:8888/drupal. This URL may be slightly different depending on your settings and folder names. Most likely you’ll want the most used starter modules, so click “standard install”. Click on “Install in English”. Fix any errors that appear; typically these are folders with incorrect permissions. Select “mysqli” as the database type, and enter your database name, user, and password (from the earlier steps). Depending on your MAMP settings, you may need to change the mysql port under “Advanced options”. The default for MAMP is 8889.

Continue to the next step. Enter the site name and email. Enter an administrator username, email, and password. Set the default country and timezone. Click “Save and continue” and the site is complete. Now you may “Visit your new site” and you will be taken to the front page of your local Drupal development site. Now you may develop away on your local machine with or without an Internet connection!