Monday, November 2, 2009

HOWTO: Fix login problem after a fresh installtion

This post is for people who have problem with login to admin panel on a fresh installation of Magento (man, this bug has been reported one year ago!). I myself got the bug on my computer this morning too, I did some searches and finally got a solution that worked for me. I don't know why Magento Team do not fix this bug yet, it's not so complicated too fix anyway. So here is a few thing for you to check if you can't login to Magento panel.

1. Use your IP Address
Use your local ip address as hostname. It should be 127.0.0.1 for 99% cases.

I must admit this is a very stupid bug. If you know how browser works, you will understand the problem. Magento want the cookie is also available for sub-domains as well, and to do it you will have to prefix the host name with a "." (dot). If you hostname is magento.com, then the host name to save the cookie is .magento.com. So when you work on local machine, your domain is localhost and magento will save the cookie under .localhost and the problem begin: browser does not save cookie on top-level domain, i.e: .com, .net, .org, etc ... And .localhost is a top-level domain (you can count the dots) and Magento broken. When you use your ip address, Magento will save it under .127.0.0.1 and it's not a top-level domain, so it works. For people who don't like to use your ip address, you can try to edit your local hosts file. I usually use local.dev for my development.

Noted: if you have already setup your url in configuration page to localhost then using the IP won't work, refer to the next section to know how to change your configuration directly in the database.

2. Check your setting
Sometime, thing goes wrong because of your configuration. You can check for timezone setting and base url setting. If your url is wrong, browser won't save your cookie at correct location and the result is you can't login to your Magento site. The same with Magento Timezone setting too.

If you can't access your admin panel to change your timezone setting. You can do this via phpmyadmin or similar tools. Go to core_config_data table and search for general/locale/timezone by path field then change it to your current timezone (use this list to look up your timezone)


You can do the same with  web/unsecure/base_url and web/secure/base_url. These are url configuration entries. Make sure you change values for all scopes and scope id, this is to avoid mistake.

3. Change session storage to file system
I don't think this is a correct solution, but some people say that it works for them so I include it here for reference.

Open app/etc/local.xml, look for

<session_save><![CDATA[db]]></session_save>
and replace with
<session_save><![CDATA[files]]></session_save>

Flush all sessions by truncate the core_session table and delete every items in var/session and var/cache. Hope it may work :)

Here are some links for your references:

2 comments:

  1. It feels good to find such an interesting topic on the internet like this one nowadays. I was greatly interested with what you have shared and posted with us. Thanks for this anyway. magento checkout

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete