An issue I’ve encountered with MAMP Pro since having upgraded to OS X Lion was that requests to vhosts served via MAMP took their time to load: after about 3 to 5 seconds of loading, the site would finally load.
The most tricky part in this issue is that it only happens if you have a domain ending in .local
, such as mysite.local
. If you’d rename the site to mysite.dev
, it’d be — … beware, buzzword coming up … — snappy again.
Turns out, after a few Google Search Coupons, that the culprit is Bonjour (emphasis mine):
The Multicast DNS feature of Bonjour technology allows devices on a local network to connect to each other by name without a separate DNS server. By default, any hostname ending in .local is treated as a Bonjour host rather than by querying the DNS server entries in Network preferences.
Though the .local domain is not defined as a valid top-level domain on the Internet, some private networks have DNS servers that assign hostnames in the .local domain. By default Mac OS X does not use the DNS server to resolve these names. This may result in unexpected failures to connect to .local hostnames defined by your server.
To fix this problem (without having to rename each vhost) you need to add IPv6 entries for each of your vhosts in your /etc/hosts
file:
::1 mysite.local
fe80::1%lo0 mysite.local
127.0.0.1 mysite.local
After that, .local
vhosts load fast again. I’ve created an issue on the MAMP bug tracker for this, requesting the author to automatically add IPv6 entries to the hosts file when creating/editing a vhost. Hope to see this fixed in a future version. For now, the fix above will have to do.
Note that after restarting MAMP, the IPv6 entries will be gone … yeah, so that bug needs to fixed soon (either by Apple, or by MAMP). If you don’t want all the hassle after a restart, you might consider renaming your vhosts to UPDATE 2011.12.18: If you tab-delimit the vhosts (a rather unknown trick) for the .dev
(anything but .local
will do)::1
entry, MAMP won’t delete it when reloading MAMP/adding a new vhost. Eventually, your hosts file will look like something 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 mysite.local myothersite.local anothersite.local yetanothersite.local
fe80::1%lo0 localhost
127.0.0.1 mysite.local
127.0.0.1 myothersite.local
127.0.0.1 anothersite.local
127.0.0.1 yetanothersite.local
Consider donating.
I don’t run ads on my blog nor do I do this for profit. A donation however would always put a smile on my face though. Thanks!
Awesome, what a time saver!
Was having the same issue.
Just what I needed, thanks!
Oh, thank heavens!! This has been bothering me for a while. Finally a straight answer. Thank you!
So many (many many many many many …) thanks for this!
Thanks! The slow resolving was bugging me for a long time, but never been able to solve it… Now my dev server is alive and kicking again 🙂
This also applies to Leopard and under Windows 7 (!) as well – adding the hosts to ::1 makes .local really fast 😉
Thank you so much for this! I thought my framework was just acting slow until I tried it on a brand-new local site. This was driving me nuts!
Thanks a lot for the tip! Blazing fast again 🙂
Brilliant! Thank you for the concise, quick fix.
Thank you! After all the “just dont use .local”-fixes finally one that works without changing all the dev-tlds!
Wohoo! Thanks!
Mind the space after ::1 and localhost and then tabs to your local sites.
I’m a new Mac user and couldn’t figure this out for love nor money as I never had any problems on windows and WAMP.
I, my Mac and iPad thank you V much.
Using .dev has the same issue. Adding the IPV6 vhost entries resolves this. Becoming an epic pain if you’re serving many vhosts with MAMP Pro.
MAMP 2.0.5 on Lion.
Had the same problem with .local addresses on Mountain Lion.
This fixed it, Thank You!
Thanks. Solved my problem.
Brilliant! Thanks for this … I ran into the exact same issue.
I’m developing a facebook application and I was going crazy with this lion fail.
I was searching how to activate in mysql the slow queries to trace the problem and suddenly your answer appears :))
Thank you for avoid me a big headache.
This is a FANTASTIC find! I cannot tell you how many weeks I was racking my brains on this one. And to top it off, I have a Windows 7 laptop along with my dev desktop and I do NOT have this issue on there….the reason…I do NOT have any apple software installed on the laptop! This post just answered the “why does my laptop not have this issue?” question for me.
I have a small article written up on my site as well, but I am going to update it with a link back to this little gem 😉
Thanks for solving this dilemma!
Follow up comment on this.
I did some more experimenting on this and discovered that even if I do not update the hosts file with the ipV6 data, I can have my site.local on any line that starts like
127.0.0.1
As long as it is not the FIRST entry in the file (windows) it works:
127.0.0.1 site site.local
If I move site.local to be first before anything else on that line, it will break. Normally I would create my hosts as:
127.0.0.1 site.local site (This will break)
So now I do:
127.0.0.1 site site.local (This works after I restart Apache)
Not sure how that fares with the bug you mention in your post, but thought I would pass this along too….I will update my post on my site as well.
Chris, thanks for your reply. Wasn’t aware it also affected Windows computers, yet now that you’ve mentioned it it’s rather logical indeed (as it’s Bonjour, which also exists on Windows). You’ve found a rather strange fix, but that doesn’t surprise me as it’s a strange bug to begin with 🙂
Wow. I didn’t even read the whole post. I immediately just went and changed my .local to .dev and my locally running WordPress admin just got a lot more… snappy.
Why doesn’t it work for me (using Mountain Lion)? In MAMP Pro 2.1.2 i’ve created my new host called “devhost” then added the following on top of the hosts file:
127.0.0.1 devhost localhost
::1 devhost localhost
fe80::1%lo0 devhost localhost
When I restart MAMP, it kicks out those lines and again adds its own which are:
127.0.0.1 localhost
::1 localhost
255.255.255.255 broadcasthost
Not only that it kicks out my lines – it bothers me it even doesn’t mention “devhost” anywhere throughout. What have I missed? I delimited with tabs all the way, as described…
Thank you Bram. Your tip helped me reduce my frustration with waiting for my dev site to reload today 🙂
Thanks, you save my life. 😉
Thanks.
Works perfectly – thanks for posting.
So here is the problem: it didn’t work for me because i was using php 5.5.3 in mamp. so here is what you do if your using that one.
it explains it here:
http://stackoverflow.com/questions/19073270/stop-caching-for-php-5-5-3-in-mamp
your php.ini file should look like this:
;[OPcache]
;zend_extension=”/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-;debug-non-zts-20121212/opcache.so”
; opcache.memory_consumption=128
; opcache.interned_strings_buffer=8
; opcache.max_accelerated_files=4000
; opcache.revalidate_freq=60
; opcache.fast_shutdown=1
; opcache.enable_cli=1
This is still a fix in 2023. Thank you!