postimg
Jul 2010 25

If your reading this, then you probably know what MAMP is, but for those still in the dark – The abbreviation “MAMP” stands for: Macintosh, Apache, Mysql and PHP. You can learn more about MAMP here.

Objectives

1) Set up MAMP, so that your websites can sit in your SITES folder (not in the nasty htdocs folder.. yuk)
2) Turn your local dev URLs from this ugly URL: http://localhost:8888/dangermoose to this super cool and easy URL: http://dangermoose.dev

“During this guide, I will refer to how I have set up my development site for dangermoose. So, where you see the the text dangermoose just replace it with the name of your site”

Installing MAMP

If you have already installed MAMP, feel free to put the kettle on, while your counter parts read on.

1) Installing MAMP is easy (isnt everything on a mac?), simply download the latest free version from here and unzip the downloaded file

2) Once unzipped, double click the mamp.dmg file

Downloaded MAMP

3) You should see this user agreement, click Agree

Agree to MAMP install

4) Hopefully, you’ll see something like the image below. Drag the MAMP folder (NOT the MAMP PRO) to the Applications folder and pat yourself on the back – MAMP is now installed.

Pic of Select a MAMP version

Testing MAMP is working

1) Go to your Applications folder, there should be two entries that say MAMP. One of these is the application itself (the one with the grey icon), the other is where the MAMP files reside (we’ll get to that later).

2) Double-click on the grey MAMP icon to start MAMP (you might also want to drag the MAMP grey icon to your dock for future use).

MAMP in your applications folder

If everything is working, your default browser should open a new tab and display the MAMP starting page. Hopefully something like this:

Welcome to MAMP screen

If you can see this screen, it’s a good start. It means the default web server settings are running as sweet as a nut and as far as MAMP is concerned, your web server is running as smooth as ever. If for some reason the starting page does not display, sadly the reasons for this are beyond the scope of this guide, but alas, the MAMP support forum is pretty darn helpful.

If you want (and many people do), you can start to use the webserver as it is. Just put your website folders inside the Applications > MAMP > htdocs folder, then navigate to this URL http://localhost:8888/dangermoose/ and with a bit of luck, your website is there in all it’s glory!

MAMP htdocs folder

Set up your MAMP like a Dev King

Many folk are comfortable using the default settings, in fact some preach by it and I’ll be the first to say that’s just fine.

“If it isn’t broke don’t fix it”

If on the other hand, you would prefer to see your website at http://dangermoose.dev AND store all your websites in the /Sites/ directory, then we can do this too.

There are a few steps involved, so let’s be precise and go through each one in detail.

Step 1 – Setting up MAMP to use your /Sites/ directory

As mentioned above, MAMP by default points to the default location of Applications > MAMP > htdocs, but if your reading this far, it means you (like me) probably prefer to keep your websites stored in the sites directory (on my mac it’s /users/flashmac/Sites/)

Showing a folder of the sites location

Luckily, this is simple. Once you have MAMP running, click on the MAMP grey icon (did you drag it to your doc?) and you should see a small window like so:

Mamp preferences menu

Click the preferences button and click the forth tab named ‘Apache’, then just enter the location of your Sites folder.

MAMP preferences apache

MAMP should now be pointing to your Sites directory.

Typing http://localhost:8888 will show you the contents of your /Sites/ directory.

Typing http://localhost:8888/dangermoose.dev will show me the contents of my /Sites/dangermoose.dev directory.

While we’re in the preferences tab, go ahead and click on the second tab named ‘Ports’. By default your Apache port is probably set to 8888. This is the port number for MAMPs version of Apache – because we don’t want to have to type in that ugly 8888 port number in our URL every time, we can change MAMP to use the Macs very own built in Apache which resides on port 80. Go ahead, change the port number from 8888 to 80.

MAMP preferences ports

Now, instead of http://localhost:8888, we could type http://localhost:80 or just http://localhost (see no more typing 8888 mumbo jumbo)

Just for the record, here is how the other preferences should look.

MAMP preferences start
MAMP preferences php

Step 2 – Add your site to the hosts file

We need to add your dev site to the hosts file, so in my case, I have a development copy of dangermoose in a folder called ‘dangermoose.dev’ (the location of this folder is /Sites/dangermoose.dev), it could quite easily be called ‘dangermoose’, the suffix of ‘.dev’ is just a habbit of mine, you don’t really need this.

If you haven’t the foggiest where your hosts file is, don’t worry, you can easily locate it by with a crafty shortcut:
Open Finder and press OPT + SHIFT + G.

GO TO Folder cmd

At this point you should see a pop up titled ‘Go To Folder‘. Simply type in /etc/ like above and click GO.

You should now be inside the /etc/ directory. Scroll down until you find the hosts file and open it in your favourite text editor.

The hosts file

If your not familiar with the host file, don’t worry, again it’s fairly easy – it’s just a way of getting your browser to redirect one URL to another location. Take a look at the image below, you can see I have just added one line of text “127.0.0.1 dangermoose.dev”.

Screenshot of the hosts file

So if your website is called SexyShoes.com and maybe your local copy is stored in a folder called sexyshoes. You need to add the text “127.0.0.1 sexyshoes“.

This is how we tell the browser that when http://dangermoose.dev (or sexyshoes) is entered into the URL, it shouldn’t go off on a tangent, instead it needs to load up 127.0.0.1 (localhost). If that in anyway confuses you, scroll down a few inches and read ‘A little story’.

Step 3 – Virtual Host

If you type in http://localhost into your browser (make sure MAMP is running), you’ll probably see a list of everything in the /Users/YourUsername/Sites directory which is nearly what we want, but not quite. I could navigate to my dev website by entering http://localhost/dangermoose.dev but what I really want (and you too I guess) is to be able to type http://dangermoose.dev (without the ‘localhost’) – no problem!

Remember after the install, there were two MAMP files in the Applications folder (Applications > MAMP), well one of them was actually a folder. If you open this and navigate your way to Applications > MAMP > CONF > APACHE, there will find a file called ‘httpd.conf’. Open this in your favourite text editor.

Screengrab of the httpd_conf file

This is where all your Apache (the web server) settings are stored. If this is new to you and floats your boat, you can google apache till your heart is content. For now, we just need to know how to set our virtual host.

Scroll down to the very bottom of the file and insert this text


<VirtualHost *:80>
ServerName dangermoose.dev
DocumentRoot "/Users/flashmac/Sites/dangermoose.dev"
</VirtualHost>

Make sure you change the path to your specific settings. So if your User is BobbyT and your website folder is called monkeynuts then you would enter:


<VirtualHost *:80>
ServerName monkeynuts
DocumentRoot "/Users/BobbyT/Sites/monkeynuts"
</VirtualHost>

This creates what is known as a virtual host for whatever you set the ServerName.

It’s time for a story.

Little Story of mamp

Now, you should (and fingers crossed) be able to view your dev sites like a true dev king!

If you want to add more than one site – no problem, just repeat steps 2 and 3 for each site.

Update: Adding Multiple Sites

Since a few of you are asking me about adding multiple sites, I thought I’d add some info on that too.

Basically there are two steps you need to take, plus something you need to do only the first time you add a multiple site. We’ll call that step 3.

1) First lets assume we have another website called anothersite.dev (this would be stored in a folder at ‘/Sites/anothersite.dev’).

You need to add this site to your hosts file just as you did for the first site (see above if you’ve forgot already)

Multiple Sites in Hosts file

2) You then need to add the new site to the http.conf just like to did for the first site. The image below shows you the new site anothersite.dev (its exactly the same as the first site, only you need to change the site name).

http.conf adding Multiple Sites

3) Some of you have told me that when you try to view your second site, your browser displays the content of your first site. This was a tough one to find, but I think I’ve cracked it. Using the same image above, the image below highlights one line “NameVirtualHost *:80” which is just above where you have edited the http.conf file. Make sure you have this line and it is uncommented (that is without the ‘#’ at the beginning). This only needs to be done once, then you should be able to add multiple sites.

http.conf Addming Multiple Sites part 2

Don’t forget to restart your apache server (restart MAMP) to ensure any changes to the http.conf file take place!

If this guide has helped you or if you experience any problems, leave a comment and lets see if we can bust a gut resolving it.

26 Comments

  1. Ardentfrost says:

    Failure for not showing the MAMP widget for your dashboard. Great bonus on an already awesome app.

  2. I got this to work with one site but when I tried to add more sites it will only accept the first one listed. Is there something I’m missing?

    • flashmac says:

      Hi Daniel,

      Glad you got it working. Now that the hard work is done, here is all you need to add multiple sites:

      Add this to the end of the httpd.conf file (mamp/conf/apache/)

      <VirtualHost *:80>
          ServerName anothersitename.dev
          DocumentRoot "/Users/flashmac/Sites/anothersitename.dev"
      </VirtualHost>
      

      then edit the host file (/etc/hosts) and add the new site address to the line with 127.0.0.1 like so:
      127.0.0.1 anothersitename.dev

      Good luck.

      Update: I’ve added a new section to the post on ‘adding multiple sites’

  3. BoxerDog says:

    Thank you, thank you … I was stumbling at the last hurdle and you put the puzzle together nicely. All up and running and very happy!

  4. Anthony says:

    Hi thanks so much for getting this online. I have had no luck though :( Some questions that I didn’t quite follow from the instructions:- I don’t know which is the file/folder on my mac that is the equivilent to your dangermoose.dev file, the closest I can find is a folder called wp-content, is that the one? And then do I actually have to move this folder to my ‘sites’ folder or not? Thanks again, from a newbie

    • flashmac says:

      Hi Anthony,

      wp-content sounds like a WordPress directory. Thats not the one! My filename.dev files are stored like so:

      /Sites/dangermoose.dev
      /Sites/anothersite.dev

      dangermoose.dev would be the root folder of your website (so yepp you have to move your website here if you’ve followed this guide)

      Hope that helps, thanks for reading!

  5. John says:

    Thanks for the great post. I think I found an error (mis-matched names) in your reply to Daniel. You wrote:

    ServerName generateaname.dev
    DocumentRoot “/Users/flashmac/Sites/anothersitename.dev”

    Shouldn’t that be:

    ServerName anothersitename.dev
    DocumentRoot “/Users/flashmac/Sites/anothersitename.dev”

    Thanks again for a very helpful article!

  6. Simon says:

    Just a small question, more of a request if at all possible (would appreciate a reply via email with yes/no…)

    MAMP. How in the name of god can we get it to run Apache 2.2+? Can it be done with MAMP? Has someone done it? WHERE!??

  7. Joshua Goggans says:

    So, I followed all of the steps and everything seems to be working fine except that the mod_rewrite in my htaccess file is not working.

    It is working fine on the live server just can’t figure out why not locally.

  8. Michel Joanisse says:

    Hi there, great tutorial – thanks a lot!
    I’m having trouble creating multiple virtual hosts.

    Here is what my ‘httpd.conf’ :

    ServerName local.website1.com
    DocumentRoot “/Users/mjoanisse/Sites/website1″

    ServerName local.website2.com
    DocumentRoot “/Users/mjoanisse/Sites/website2″

    And here is what i have in the ‘hosts’.

    127.0.0.1 local.website1.com
    255.255.255.255 broadcasthost
    ::1 localhost
    fe80::1%lo0 localhost

    127.0.0.1 local.website2.com

    -

    My MAMP document root is set as ‘/Users/mjoanisse/Sites’

    -

    My problem is whether i load ‘local.website1.com’ or ‘local.website2.com’ they both display the contents to website 1 ..

  9. Michel Joanisse says:

    Hello sir! A quick note definitely worth mentioning, when adding new sites, it’s essential that you then restart servers in MAMP, or your changes / revised copies of ‘hosts’ and ‘httpd.conf’ will not necessarily take effect.

    Cheers!

  10. Giles Smith says:

    Hi Flash, great post! Its exactly what I am doing already, but you know, great minds and all that!

  11. Ryan Salway says:

    First of all, thanks for the tutorial. I have it all working with the exception of the last step. I have this:

    NameVirtualHost *:80

    ServerName only_alpha
    DocumentRoot “/Users/ryansalway/Sites/only_alpha”

    when I go to my browser, it says page not found.

    I did find something earlier that I took for granted was okay, in the MAMP preferences, I had a choice of PHP 5.2.13 and PHP 5.3.2 (this is the one checked)
    I could not check the Zend Optimizer and the Cache was selected already to XCache. I left this alone. Would this have anything to do with it?

    I also noticed that getting to my “hosts” file, it was much different. I had to go through “terminal” to get there. When I scrolled down, there was a line that read “127.0.0.1 localhost”. I changed it to my folder. Should I have left that one there and added another line with my folder?

    • flashmac says:

      Hi Ryan,
      Im only running php 5.2* so Im unsure if choosing 5.3* would make any difference, I doubt it though and the cache preferences wont be the problem. I’d put my money on the hosts file.

      If you enter http://localhost you should see the index of your Sites folder. If not, then you need to edit your hosts file again. That might fix it.

      Good luck

  12. This worked like a charm… until at the end of the initial wizard set-up where you Create Admin Account… Magento hangs on “Waiting for Local Host”. I’ve tried everything that I could find on the intrawebs but no dice. Have you ever encountered this?

    Thanks again for such a great post!

  13. Shona Printy says:

    A large percentage of of the things you state happens to be astonishingly legitimate and that makes me ponder why I hadn’t looked at this in this light before. This article truly did switch the light on for me personally as far as this issue goes. Nonetheless there is just one issue I am not necessarily too comfy with so whilst I try to reconcile that with the actual main theme of the position, permit me see exactly what all the rest of the subscribers have to say.Very well done.

  14. Kevin says:

    Nice one, this is what I’ve been looking for all day! All the MAMP info on the net is about how to install MAMP and there is hardly anything out there about how to use it. Keep up the good work.

  15. Kay Cam says:

    Will these instructions work for a client to view the site live?

    I am developing a site on the local server, but when I copy the URL http://localhost:8888 to my client, it only shows the raw HTML. I would like her to be able to view the site to see its progress.

    Please advise on how I can do this?

    Thanks,
    Kay

    • flashmac says:

      Hi Kay,

      Not 100% sure what you mean… but…

      This tutorial is aimed at your localhost and couldnt be applied to a live server.

      If your wanting to show a client a live site whilst its being developed, you can do this many ways. I usually prefer to create a subdomain called ‘dev’ on the server and give this to the client. Something like
      http://dev.example.com

      Hope that helps.

      • Kay says:

        Okay, so it’s not possible for a client to view a site on the local server. So creating a URL would not work, then.

        I tried setting up a URL and now my MAMP site is broken. So I’ll see if I can restore it, and in the meantime I’ll set up a subdomain on my site.

        Thanks,
        Kay

Leave a Comment

<