14

This is not a question but rather an answer to a problem that is pretty old but recurring. I remember struggling on this back in the days when I was setting up Magento 1.9 and it occurred again this time around on Magento 2.1.4. I totally forgot about how I fixed it back then, so this time around I'm documenting my answer here in case someone needs it too.

Problem Statement

Basically, you were setting up your Magento 2.1 store, fulfilled all the server requirements, added SSL, setup your Website, Store and Store View and filled up the store configuration only to realise that suddenly you can't login to the admin panel anymore. There are no errors, nothing in the browser console, neither any problem with the browser Chrome / Firefox. You clear the sessions and cache to no avail too. You found answers that keep pointing back to sessions and cache settings, but you did follow the documentation, and it still doesn't work.

  • first post the question then in below click on Answer Your answer and add answer their. – Qaisar Satti Feb 20 '17 at 11:25
  • Got it. I added the official answer at the bottom as per your request. – Aftab Feb 20 '17 at 11:40
23

Emergency Fix

Whether or not this solution works, please try these steps first. You WILL be able to login which means you are on the right page. If you still could not login, your issue is most likely different than the one I'm posting, please proceed at your own risk.

  • Go to your database. If you have phpMyAdmin, do the following:
  • Click on your xxx_core_config_data table (xxx_ is the additional table prefix that you might have set during installation)
  • Once the table is selected, hit the "search" tab on the right side
  • In the search menu, under "path", select the dropdown to (LIKE %...%) and insert "cookie" in the field next to it. This will search for all table rows that contain "cookie" in their path value.
  • Delete the VALUE of the following (if you do not see some of them, just ignore. It might not have been setup yet, so you can omit it):
    • web/cookie/cookie_domain
    • web/cookie/cookie_httponly
    • web/cookie/cookie_lifetime
    • web/cookie/cookie_path

That's it. Now, refresh your admin page and try logging in. It should work. If it does, now let's get to the crux of the problem.

The Issue

Most of the time, following the guide asks us to store the cookie domain as .domain.com which is expecting a sub-domain, but the store name is stored as http://domain.com as it's base URL.

The Fix

There are two ways to fix this problem.

If you are not going to be using a subdomain for cookie storage, you can save the cookie domain settings in Stores -> Configuration -> Web -> Cookie Domain as (domain.com) without a preceding period and parentheses.

If you plan to make your store future-ready and allow subdomain cookie storage, you should set the Cookie Domain as (.domain.com) with a preceding period and without the parentheses. However, in your base URL under Stores -> Configuration -> Web -> Base URL, add www to your domain name such as http://www.domain.com and https in the secure base URL if you are using SSL (that you should).

Additionally, other Cookie Settings are as such: Cookie Lifetime - 86400 (From my understanding, you don't need this and can leave it blank and check "use system value" because now Magento retains the session for security reasons). Cookie Path - / Use HTTP Only - Yes Cookie Restriction Mode - Up to you. If you enable this, it will show the message on the front end asking the user's consent to store cookies.

Note: Once again, this one is for my own future reference purposes and for anyone who might stumble into this frustration just like I did.

  • Saved my day! Thanks! I was suspecting issues with the cookie restriction mode settings I made last time, so the problem indeed turned out to be the cookie domain value set to ".domain.com". I changed the value from the database web/cookie/cookie_domain to "domain.com" and was able to log in admin area successfully. – Iveta Allogenes Jun 20 '18 at 13:19
1

Quick Fix:

Add or Update Web Url entries to https:// secure urls for below configuration entries in database

In Table > core_config_data set below value for your store:

  1. web/unsecure/base_url => 'https://yoursiteurl.com/'

  2. web/secure/base_url => 'https://yoursiteurl.com/'

1

I experienced this after setting up a new project done previously by the other devs. On my end, this is how I fixed this.

In core_config_data table, I searched for the path web/cookie/cookie_domain. And then found out that the domain is not the same with the current project's domain. So I just changed it to be same as the current project domain. And then after that, the admin login works.

0

Soon after the Magento Installation, if you are running into the below issues: a. The admin is not able to login after successful installation b. Magento2: Error 404 not found at the magento2 admin login page after successful installation. c. The links on the admin page not working.

Perform the below steps

a. Add the extra code to the **Validator.php** file which you will generally find from below given system path.
     Path: C:\xampp\htdocs\<Your Magento Folder>\vendor\magento\framework\View\Element\Template\File

     /**
     * Checks whether path related to the directory
     *
     * @param string $path
     * @param string|array $directories
     * @return bool
     */
    protected function isPathInDirectories($path, $directories)
    {
        if (!is_array($directories)) {
            $directories = (array)$directories;
        }
        $realPath = $this->fileDriver->getRealPath($path);
        **$realPath = str_replace('\\', '/', $realPath);   <<<====== Extra Code**
        foreach ($directories as $directory) {
            if (0 === strpos($realPath, $directory)) {
                return true;
            }
        }
        return false;
    }

b. This will regenerate all the files
      # php -d memory_limit=1G bin/magento setup:static-content:deploy -f


c. This will flush all the cache from the 2 directories var and generated
      Delete files form the folowing folders
        1. var 
        2. generated

This should fix the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.