• Skip to primary navigation
  • Skip to main content
  • Skip to footer
  • Books
    • Content Strategy for WordPress (2015)
    • WordPress for Web Developers (2013)
    • Beginning WordPress 3 (2010)
  • Blog
    • Content Modeling for WordPress
    • WordPress Hidden Gems
    • Web Design
  • Work
    • MLIS Class Projects (2019-2022)
    • Portfolio (2002-2019)
    • Services
    • WordPress Plugins
    • WordPress Themes
    • Presentations and Interviews
    • on GitHub →

Stephanie Leary

Writer, WordPress consultant, recent MLIS grad

  • About
    • Press Kit
    • Presentations and Interviews
  • Contact Me

Virtual hosts with MAMP

November 6, 2007 Stephanie Leary 19 Comments

I’ve spent the last two days setting up virtual hosts with MAMP on two different Macs, one Tiger and one Leopard. I’m posting this so the next person doesn’t have to spend two days at it.

Setting up virtual hosts is really pretty straightforward, once you find a good set of instructions. (I had done this before… about three years ago. I’ve slept since then.) Dave Shea to the rescue. However, after I’d edited httpd.conf, Apache wouldn’t start. After long hours of trial, error, and searching the MAMP forum (where this problem had been often reported but never resolved), I learned that it was happening because (like any fool Mac user) I’d opened it up in TextEdit.

Don’t use TextEdit on your .conf files. It no workee. I’m guessing the problem has to do with Mac-specific line breaks, because when I edited them in Dreamweaver, which I’ve set to use UNIX-style line breaks, everything worked perfectly. I’ve seen other people report success with TextWrangler and TextMate. Of course, nano and pico work well too.

So, those evolt instructions Dave linked to were all fine and good in Tiger, but in Leopard, the NetInfo Manager application is gone. You therefore have two choices: you can edit /etc/hosts by hand (pico or nano again!), or you can use VirtualHostX. I don’t mind editing the hosts file in Terminal, but I generally prefer a nice GUI if I can get it, so I tried VirtualHostX to define my sites. Then I couldn’t figure out why I was seeing the default Apache page from /Library/WebServer/Documents rather than the servers I’d defined in httpd.conf, which used various things in my ~/Sites directory as their document roots.

Here’s the problem: VirtualHostX tries to be a little too helpful. Since it assumes that you’re using the built-in Apache rather than MAMP, it fires up Personal Web Sharing under System Prefs. Personal Web Sharing trumps MAMP, so to speak, and what you’re seeing is the other Apache installation on your system. Turn off Personal Web Sharing and everything’s fine again.

Simple, right?

Two systems. Two problems. Two days. Don’t let this happen to you.

Addendum: Lots of people have recommended Headdress for dealing with Apache config junk. When I tried it on the Tiger machine, Apache refused to start. Same problem I had with TextEdit? I dunno. I might try it again on the Leopard machine… after I back everything up. Several times.

Addendum #2: Tried Headdress in Leopard. No problems with Apache this time, but Headdress insists on using port numbers rather than server names (or aliases) to distinguish hosts — e.g. localhost:9000 and localhost:9001, rather than mysite and myothersite — because it’s not touching /etc/hosts; it’s just editing httpd.conf. It is smart enough to distinguish between MAMP and the built-in Apache, and it allows you to maintain both. Still, the port thing is bollocks. I also don’t like the fact that the details about Headdress’s operations are in its Help file, which you won’t see until you’ve installed it, rather than on the website. Oh well. Nano and I get along just fine.

For my next trick, I’m going to reinstall Windows under Parallels and get the virtual hosts working for IE testing.

Macs, Web Design

Reader Interactions

Comments

  1. matt says

    March 24, 2008 at 9:29 pm

    Can’t I use textmate to edit all necessary files?

    This is driving me crazy. I moved over to leopard from tiger, and I upgraded my MAMP. The servers seem to be running, they just aren’t connecting with my hosts.

    Could you maybe post examples of your hosts, and config files?

    Reply
  2. matt says

    March 24, 2008 at 9:29 pm

    Sorry, I meant from tiger to leopard.

    Reply
  3. Stephanie says

    March 24, 2008 at 11:11 pm

    Hi, Matt. Here’s my hosts file after the commented stuff:

    127.0.0.1 localhost
    255.255.255.255 broadcasthost
    ::1 localhost
    fe80::1%lo0 localhost

    # VIRTUAL HOST START
    127.0.0.1 sillybean wordpress
    # VIRTUAL HOST STOP

    Here’s what the end of httpd.conf looks like:


    #
    # Use name-based virtual hosting.
    #

    NameVirtualHost 127.0.0.1

    <VirtualHost 127.0.0.1>
    ServerName localhost
    DocumentRoot /Users/stephanieleary/Sites/
    </VirtualHost>

    <VirtualHost 127.0.0.1>
    ServerName wordpress
    DocumentRoot /Users/stephanieleary/Sites/wordpress
    </VirtualHost>

    Many examples I saw used * instead of 127.0.0.1, but it wouldn’t work for me, and I have no idea why. If you have one, try the other.

    Reply
  4. Stephanie says

    March 24, 2008 at 11:18 pm

    If you got a mangled version by email… sorry about that. Textile is persnickety about code. I’ve fixed it here.

    I also left out the entry for sillybean, but it looks exactly like the others.

    Reply
  5. matt says

    March 25, 2008 at 6:24 am

    Thanks Stephanie. I’ll play around with it later. I have posted several times at the MAMP forum but it’s a lonely place in there.

    Reply
  6. Stephanie says

    March 27, 2008 at 12:30 am

    Tell me about it! I’ve had at least a dozen problems with it, and solved eleven of them myself (with attendant Googling, facepalming, and headdesking).

    Reply
  7. Stephanie says

    March 28, 2008 at 8:58 am

    Matt, did you ever get your problem sorted out? I’m now running into the same situation on another Leopard machine. :(

    Reply
  8. Matt says

    March 28, 2008 at 9:15 am

    I haven’t had time to play around yet. I’m going to try to pull aside one of our lead developers at work and fix it. He’ll take care of it I’m sure. I’ll share my results.

    Reply
  9. Stephanie says

    March 28, 2008 at 4:44 pm

    I finally got mine working. I had to place each named host on a separate line in /etc/hosts rather than having them all on one. Now it looks like:

    notextile.. # VIRTUAL HOST START
    127.0.0.1 sillybean
    127.0.0.1 wordpress
    # VIRTUAL HOST STOP

    I had to use dscacheutil -flushcache in Terminal to flush the DNS cache, but then my virtual hosts started right up. I made some changes to httpd.conf while mucking around… among other things, I’d found a reference that the DocumentRoot paths had to be enclosed in quotes in Leopard. Not sure if that actually did anything, though. (Now that it’s working, I’m not touching it.)

    Reply
  10. Matt says

    March 28, 2008 at 4:51 pm

    Interesting. It certainly is cleaner that way. By the way. I the developer sat down at my machine, popped open terminal, and within about a minute had my problem fixed.

    The solution: I had the virtual host section of the conf file commented out. It’s the little things that get you.

    Reply
  11. Marcus Mucha says

    April 16, 2008 at 1:07 pm

    I’m on Leopard and am trying to get multiple sites up with MAMP, but I can’t seem to get this working. I was curious what your Port settings are within MAMP?

    Also, which .conf file are you modifying? the one at “/Applications/MAMP/conf/apache/httpd.conf” ? OR in the case of Leopard “/private/etc/apache2/extra/httpd-vhosts.conf” ?

    I have all my sites set up in a sub-directory under “Documents”. I’m wondering if it is critical that I have them under “Sites” instead?

    Any tips or help would be most appreciated!

    Reply
  12. Matt says

    April 16, 2008 at 1:34 pm

    Don’t keep your directories in Documents. Keep them within the mamp folder.

    Edit the /Applications/MAMP/conf/apache/httpd.conf file.

    Keep the ports set to default. Apache: 8888, MySql: 8889

    Reply
  13. Stephanie says

    April 16, 2008 at 9:01 pm

    Marcus: it doesn’t matter much where you have the files stored, as long as your httpd.conf file (the one Matt specified) references them correctly.

    I use the Apache & MySQL defaults in MAMP, but Leopard requires an admin password every time you start Apache on port 80, so that’s an annoyance you have to live with if you choose that port. (I think Tiger did the same thing, in fact.)

    Reply
  14. Andy says

    June 2, 2008 at 3:13 am

    Hi everybody,

    I just have a question (excuse me for my bad english!). Is it possible to create a virtual host for the apache start page? So you can type just ‘mamp’ instead of ‘http://localhost:8888/mamp/&#8217;?

    If yes, how can I do it?

    Thank you so much!

    Reply
  15. Stephanie says

    June 2, 2008 at 10:42 am

    Hi, Andy. You can. Just add this to the end of httpd.conf (use localhost instead of 127.0.0.1 if that’s what you’ve done elsewhere):

    @
    ServerName mamp
    DocumentRoot /Applications/MAMP/bin/mamp
    @

    And then add “mamp” in /etc/hosts, as in comment #9.

    However, you’d have to type “mamp:8888″ unless you change the MAMP preferences so that Apache uses its default port, 80, instead of the MAMP default.

    Reply
  16. Andy says

    June 6, 2008 at 1:42 pm

    Thank you so much dear Stephanie!

    Now it works perfectly! =)

    Have a great weekend!

    Cheers from Switzerland ;D

    Reply
  17. Stephanie says

    June 9, 2008 at 8:17 pm

    Really glad your questions made me post bits of my /etc/hosts file here, because I just discovered that Archive & Install does not preserve that file. ARGH.

    Reply
  18. Daniel says

    April 26, 2009 at 10:28 am

    If any of you have had problems migrating from Headdress to VirtualHostX, I’ve detailed my steps on how I got it working here:

    http://www.hyperarts.com/blog/moving-from-headdress-to-virtualhostx/

    Reply
  19. Gerald says

    April 11, 2017 at 1:19 pm

    Greetings. 2017 and I am having issues with this. Not sure if anyone is still watching or helping on this topic, but I am at my wits end, as I have read You, @Stephanie was way back when.

    Hopefully there are still people able to help as everything I read, I do, it does nothing. I know some other setting is off.

    – gerald

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Footer

My Books

I’m a front end developer at Equinox OLI, working on open source library software. I was previously a freelance WordPress developer in higher education. You can get in touch here or on LinkedIn.

Copyright © 2023 Stephanie Leary · Contact