Problem Magento 2 Can’t Login to Admin
Table of Contents
Following the update of your Magento store to the latest version, you completed the necessary setup tasks, including meeting server requirements, implementing SSL, configuring your Website, Store, and Store View, and providing details in the store configuration. However, you encountered a sudden that Magento 2 can’t login to admin anymore.
Despite thorough checks, there are no error messages, or console issues in Chrome/Firefox, and clearing sessions and cache did not resolve the problem. You had found answers that keep pointing back to sessions and cache settings. Then, you did follow the documentation, but it still doesn’t work.
Be glad that this article is the solution for you.
The solution to Solve Magento 2 Can’t Login to Admin
Emergency Solution
Before proceeding further, try the following steps to see if you can successfully login.
The steps provided involve accessing the database through phpMyAdmin and modifying certain values in the xxx_core_config_data:
Steo 1: Access your database using phpMyAdmin or a similar tool.
Step 2: Select the xxx_core_config_data table (you can also replace “xxx_” with your table prefix).
Step 3: Use the search function to find rows containing “cookie” in the “path” column.
Step 4: Delete the values of the following paths, if present:
web/cookie/cookie_domain web/cookie/cookie_httponly web/cookie/cookie_lifetime web/cookie/cookie_path
Step 5: Refresh the Magento admin page and attempt to log in.
Now, if you still encounter login issues after following these steps, the problem may be different, and further investigation is recommended.
The Fix for Login Issue
If the Magento 2 cannot login to admin problem still cannot be resolved, perhaps you have another problem caused by domain cookies. Typically, the instructions advise setting the cookie domain as .domain.com, expecting it as a subdomain. However, the store’s base URL is registered as http://domain.com. The conflict appears here.
There are 2 ways to address this problem.
- Solution 1: If you don’t intend to use a subdomain for cookie storage
Go to Stores -> Configuration -> Web -> Cookie Domain, and set it as domain.com without a preceding period and parentheses.
- Solution 2: If you plan for the future that allows setting cookie storage
For the first, you should set the Cookie Domain as .domain.com with a preceding period and without the parentheses. Next, in the base URL configuration under Stores -> Configuration -> Web -> Base URL, add “www” to your domain name, like http://www.domain.com. If SSL is implemented (which is recommended), ensure the secure base URL includes “https” as part of the setup.
As a final step, don’t forget to check other Cookie Settings as follows:
- Cookie Lifetime: 86400 (Consider leaving it blank and checking “use system value” for enhanced security.)
- Cookie Path
- Use HTTP Only: Yes
- Cookie Restriction Mode: Choose according to your preference. Enabling this option prompts users on the front end for cookie storage consent.
This information is documented for future reference and to assist anyone encountering similar frustrations.
Conclusion
Above are some of our solution suggestions for some cases where Magento 2 can’t login to admin. Hopefully, your problem has been resolved.
BSS Commerce is proud to be one of the leading Magento 2 extension providers and web development services in the world. We provide more than 180+ extensions as well as other services to meet all your problems with your Magento store. If you encounter any problems with your Magento store, do not hesitate to contact us for answers.