Why I can not login to magento 2 backend using google chrome

Why I can not login to magento 2 backend using google chrome

October 9, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Why I can not login to magento 2 backend using google chrome

Solving Magento 2 Backend Login Issues on Google Chrome

If you’re struggling to log into your Magento 2 backend using Google Chrome, don’t worry—you’re not alone! This common issue often stems from the browser’s cookie settings and can be easily resolved by modifying some core files. Let me walk you through this process step-by-step.

Identifying the Root Cause

In previous versions of Magento (1.x), the fix involved commenting out specific lines in the Varien.php file located at app/code/core/Mage/Core/Model/Session/Abstract/. However, with the switch to Magento 2 and its updated folder structure, this approach no longer works.

The problem lies in how Google Chrome handles secure cookies. By default, it doesn’t allow third-party cookies unless you manually allow them for each domain. This can interfere with Magento’s authentication process when accessing the admin panel via a non-secure connection (HTTP).

To resolve this issue, we need to modify two files in your Magento 2 installation:

  1. app/code/Magento/Framework/App/Request/Http.php

    • Locate the file and open it in a text editor.
    • Look for the following lines:
      $domain = parse_url($request->getUri())['host'] ?? '';
      
    • Replace them with this updated version:
      $domain = parse_url($request->getUri(), PHP_URL_HOST) ?? '';
      
  2. app/code/Magento/Framework/App/Request.php

    • Open this file in a text editor.
    • Find the following line:
      public function setSessionId($sessionId)
      
    • Add the line immediately after it:
      $this->getHttp()->setSecure(false);
      

Enabling Secure Cookies for Local Development

If you’re working in a local development environment, you might need to configure your server to serve secure cookies. For Apache users, add or update these lines in the VirtualHost configuration file:

<IfModule headers_module>
    Header always set X-Content-Type-Options "nosniff"
    # Add these two lines
    Header set Secure "1"
    Header set HttpOnly "1"
</IfModule>

Best Practices for Production Environments

In a production environment, it’s crucial to ensure your server is configured correctly:

  1. Use a valid SSL certificate.
  2. Configure HTTPS redirect in the .htaccess file:
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

Conclusion

Fixing this login issue requires a bit of core hacking, but it’s essential for maintaining secure cookie settings in your Magento 2 installation. Remember to always backup your files before making changes and never enable setSecure(false) on live production servers.

At Laravel Company, we specialize in providing expert Magento development services. If you find yourself stuck or need further assistance with your e-commerce setup, feel free to reach out to our team of experienced developers for professional help.

Magento 2 Themes Admin Configuration

Our network