x
 
Create New Page
 View Previous Changes    ( Last updated by Dirk Einecke )

MAMP setup

Table of Contents


Overview

The abbreviation MAMP stands for: Macintosh, Apache, Mysql and PHP. With just a few mouse-clicks, you can install Apache, PHP and MySQL for Mac OS X!

MAMP installs a local server environment in a matter of seconds on your Mac OS X computer, be it PowerBook or iMac. Like similar packages from the Windows- and Linux-world, MAMP comes free of charge.

This tutorial is intended to help you setup the free version of MAMP. MAMP PRO comes with an interface to handle this.

Download

http://www.mamp.info/en/downloads/index.html

Requirements

Mac OS X
Free Version of MAMP

Basic Setup

Once opened, the .dmg file contains the MAMP folder. Copy the whole folder into your /Applications/ directory.

Launch /Applications/MAMP/MAMP.app. You are ready to go.

Your localhost root directory is setup in /Applications/MAMP/htdocs/

Advanced Setup

For those who like run MAMP as close to a live server as possible, here are a few tricks.

1. Create a directory of choice to be your server’s document root. This is optional. You can use the default document root if you like. I personally want my server to be as close as possible to a real Unix environment; that means Case Sensitive.

*Leopard* - My preferred setup consists of a Case Sensitive partition. You can repartition your hard disk creating a new partition called www. Once the partition is created you need to erase it in order to get the option for Mac OS Extended (Case-Sensitive, Journaled).

This will generate a new drive accessed at /Volumes/www/

2. Launch /Applications/MAMP/MAMP.app and click on Preferences.
• Under the tab Start/Stop, check the appropriate boxes. I only check the first one.
• Under Ports, click on “Set to default Apache and MySQL ports”.
• Under PHP, choose the version of PHP you are developing for.
• Under Apache, browse for the directory we just created in the previous step, or use the default one.

Note. Your new Document Root is ready to use. However you can only run one website. Read along for more configuration tips.

Virtual Hosts

In order to be able to create your own sites and have them run separate from each other, we need to setup one or more Virtual Hosts (vhosts). Vhosts map url requests to directories in your system. In order to enable Virtual Hosts we need to add a few lines at the bottom of the Apache configuration file.

Open /Applications/MAMP/conf/apache/httpd.conf in your favorite text editor and add the following lines to the very bottom.

### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs-2.0/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#

# NameVirtualHost *:80

# <VirtualHost *:80>
#     ServerName www.domain.com
#     ServerAlias domain.com *.domain.com
#     DocumentRoot /Volumes/www/vhosts/domain.com
# </VirtualHost> 

Notice that lines starting with a # are comments. This will serve as a template for you vhosts. The reason they are commented out is you can have a reference when adding your working vhosts.

Uncomment the line

NameVirtualHost *:80 

This tells Apache we are using vhosts. This disables the default localhost so what we have to first after enabling Virtual Hosts is to specify the localhost.

Type these lines at the bottom. (it is a good idea to type the first one. This file is very sensitive to line breaks. It often doesn’t work to copy and paste from an external source. Once you have written you first vhost declaration, you can copy it and paste below for additional vhosts).

<VirtualHost *:80>
     
ServerName localhost
     DocumentRoot 
/Volumes/www/
</
VirtualHost

You can add as many vhosts you want below this. Every vhost must point to a physical directory.

<VirtualHost *:80>
     
ServerName my.domain.com
#     ServerAlias domain.com *.domain.com
     
DocumentRoot /Volumes/www/vhosts/domain.com
</VirtualHost>

<
VirtualHost *:80>
     
ServerName my.domain2.com
#     ServerAlias domain.com *.domain.com
     
DocumentRoot /Volumes/www/vhosts/domain2.com
</VirtualHost>

<
VirtualHost *:80>
     
ServerName my.domain3.com
#     ServerAlias domain.com *.domain.com
     
DocumentRoot /Volumes/www/vhosts/domain3.com
</VirtualHost

The next step is to fake a DNS server so we can just type my.domain.com on a browser and get the contents of /Volumes/www/vhosts/domain.com

The hosts file

Unless you have a real server with DNS entries pointing to it, the world doesn’t know you are serving web pages. So does your browser. Unless you have a way to tell your browser to look within your server before it looks on the internet, you will never get this pages to display on the browser.

Every computer has a hosts file. It keeps a list of address and their ip addresses. By entering our own lines we can tell the computer where to look for certain names. Lets start by adding a couple of lines in our hosts file.

Open Terminal and type the following:

sudo vim /etc/hosts 

enter your password.

This opens /etc/hosts with the vim editor. You can also use pico instead.
If you are using vim, click <a>, it tells vim you want to add text. Position the cursor at the desired location and enter the following lines:

127.0.0.1    my.domain.com
127.0.0.1    my
.domain2.com
127.0.0.1    my
.domain3.com 

A complete hosts file looks similaqr to this:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80
::1%lo0     localhost

##################################
# local directories
##################################

127.0.0.1       www
127.0.0.1       test
127.0.0.1       dev

##################################
# my sites
##################################

127.0.0.1    my.domain.com
127.0.0.1    my
.domain2.com
127.0.0.1    my
.domain3.com

##################################
# rackspace
##################################

96.150.62.212   rs-www1
96.150.62.213   rs
-www2
96.150.62.214   rs
-db 

Click <esc> to exit editing mode then hold <shift> and click <z><z>
This will save and close the file. For more information on the vim editor click here.

Note. Whenever editing httpd.conf or php.ini, you must restart MAMP in order to get the changes take effect.

You don’t need to restart MAMP when editing the hosts file.

That is it for Apache and Virtual Hosts.

MySQL

MAMP comes with phpMyAdmin so you can manage you MySQL databases. You can access your phpMyAdmin here

• MAMP <= 1.7.2: http://localhost/phpMyAdmin/
• MAMP >= 1.8: http://localhost/MAMP/phpmyadmin.php

For full control of MySQL from the command line add the following lines to your ~/.bash_profile or ~/.profile

alias mysql='/Applications/MAMP/Library/bin/mysql'
alias mysqladmin='sudo /Applications/MAMP/Library/bin/mysqladmin'
alias mysqlstop='sudo /Applications/MAMP/Library/bin/mysqladmin -u root -p shutdown'
alias mysqlstart='sudo /Applications/MAMP/Library/bin/mysqld_safe' 

Now you can access MySQL from the command line fairly easy.

By default, the root password = root

List of configuration files

This are important files to know as you may need to edit them for fine tuning your server.

• /etc/hosts
• /Application/MAMP/conf/apache/httpd.conf
• /Application/MAMP/conf/php4/php.ini
• /Application/MAMP/conf/php5/php.ini

Category:System Category:localhost Category:MAMP Category:Development

Category:EE1