27

On a basic installation of MAMP, I'm building an application with CodeIgniter locally (MacBook Pro, Core2Duo 2,26 GhZ, 4GB RAM).

My problem is, that when I reload a page, it does load very slow, even slower than when I put on a web server.

It's strange that it only loads slow when I reload the page, not when I click on a link in the application itself.

The application uses a MySQL database, but even when I reload a page that doesn't make MySQL queries, it's so slow, that it takes about 10 seconds to load a page.

I read on http://forum.mamp.info/viewtopic.php?f=6&t=14081 that I could try to change the server name from .local to .dev. But I don't know how to do that and didn't find anything when I googled it.

What could I do about it?

Gchtr
  • 2,379
  • 1
  • 14
  • 25

3 Answers3

40

The '.local' domains conflict with Bonjour, which treats anything with a '.local' TLD as a Bonjour server.

I found the answer here: http://www.bram.us/2011/12/12/mamp-pro-slow-name-resolving-with-local-vhosts-in-lion-fix/, and that post refers to https://discussions.apple.com/message/15834652#15834652.

The solution is to, as Jon said, put a ::1 address in/etc/hosts.

::1 localhost   example.local    anotherexample.local

Unfortunately, MAMP Pro will delete the entry when it restarts so put a tab (not spaces) between the IP and each of the hosts.

The alternative is to put a different TLD - .dev or something like that.

Dan Blows
  • 19,395
  • 9
  • 60
  • 93
  • 1
    may I ask why your dev installs end with .local? default MAMP sites are like this: http://localhost:8888/your_site – Beda Schmid May 01 '15 at 16:45
  • @beda69 In my case it was because I was working in an agency that 200 or so websites and everybody else used .local TLDs. File paths were relative to root. I use Vagrant and Gas Mask now. – Dan Blows May 01 '15 at 18:11
  • This seems to have fixed my issue, though mine was slightly different. I used .dev for my local domains. This worked fine for 99% of the time, but whenever I connected to 'The Cloud' public free WIFI, it tanked and went very slow. Making an entry this way as you describe solved the issue. Really weird! – Michael Giovanni Pumo Nov 25 '16 at 12:23
  • use .localhost it was made for that. – gagarine Apr 01 '20 at 16:15
18

To solve the problem with .local domains on OSX, do the following (assuming your site is called mysite.local):

  1. Open your /etc/hosts file in a text editor
  2. Add the following entry on its own line ::1 mysite.local
  3. Save the file

This should resolve your issue.

doitlikejustin
  • 6,107
  • 2
  • 37
  • 64
Jon
  • 2,769
  • 2
  • 13
  • 16
  • This is it. Now it's as fast as it should be. Thanks a lot! – Gchtr Dec 09 '11 at 22:49
  • 3
    What does that do? Is that supposed to be some wildcard? I thought that wasn't possible on OSX.. – Yes Barry Dec 09 '11 at 23:21
  • 4
    OSX 10.7 uses [Multicast DNS](http://www.multicastdns.org) for Bonjour which has the .local TLD reserved. Adding this hosts entry defines the domain for IPv6 which causes OSX to skip the Bonjour lookup (which times out, creating the speed issue). – Jon Dec 10 '11 at 00:28
  • Ok, after working some hours with the new hosts settings, it's again very slow. I also tried xampp, which, however, showed up with the same poor performance. I'm now developing online, which is much faster, but I think that's quite paradox... Do you maybe know another solution how to get it working as fast as it should on OSX 10.7? – Gchtr Dec 10 '11 at 20:34
  • @Purr does it work better if you use something else then .local? – Mattias Wadman Jan 28 '12 at 14:38
  • This also seemed to fix a slowness issue i was having with mysite.dev – Jordan Sitkin Jul 10 '12 at 14:07
  • @Mattias Wadman: No, it doesn't really work better. It tried it with mamp.dev and I'm sure that I correctly applied the recommended settings for the hosts file. – Gchtr Oct 07 '12 at 20:43
  • Ok, I flushed DNS cache with `dscacheutil -flushcache` and now it seems to work... for now. I will test it for some more time to see if that's what solved the problem, – Gchtr Oct 12 '12 at 18:47
  • My MAMP resolves to localhost:8888 and adding localhost:8888 doesn't seem to be working. Any ideas? Really appreciated. – JordanBelf Oct 03 '17 at 21:16
2

If on OS X Yosemite. The edit to the localhost file will not fix it. You will need to do the following.

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist

The fix is via https://coderwall.com/p/ylchfq. Update is in the comments.

Saint48198
  • 121
  • 2