Local Magento with MAMP – Unable to login to admin

I’ve probably already blogged about this but I’m sticking it on the new site so I don’t forget where I put it…

There’s a little bug with MAMP and Magento – this bug occurs when you try to login to the admin area.

When using MAMP we normally browse our local website by using http://localhost:8888. Unfortunately Magento does not allow itself to set cookies for this type of domain name. It will simply access your login credentials and then kick you back to the admin login screen.

To fix this locally, you can either change your URL so that you are using instead of localhost:8888 or alternatively you can edit the following core file (just make sure when you go live you undo this change).

In app>code>core>Mage>Core>Model>Session>Abstract>Varien.php find the following code and comment out the line as shown:

        // session cookie params
        $cookieParams = array(
            'lifetime' => $cookie->getLifetime(),
            'path'     => $cookie->getPath(),
            'domain'   => $cookie->getConfigDomain(),
            'secure'   => $cookie->isSecure(),
            //'httponly' => $cookie->getHttponly()

That should do the trick!