Whenever I tried to add product to cart from list page or product page in fresh setup Magento Ce 2.1 release it redirects to checkout page and no product gets added.

I tried disabling cache also.

4 Answers 4


If you ran in local and your path is :localhost please replace "localhost" to "".
So you can change root URL by SQL query:

UPDATE core_config_data 
SET value = '' 
WHERE path IN ('web/secure/base_url', 'web/unsecure/base_url');

It is sufficient for Magento 1.x but not for Magento 2.0. Magento 2.0 for some strange purpose additionally stores root URL in the third path: design/head/includes

The record looks like:

<link  rel="stylesheet" type="text/css"  media="all" href="<root URL>/pub/media/styles.css" />

So you need one more SQL query:

UPDATE core_config_data
SET value = REPLACE(value, '<old root URL or domain>', '<new root URL or domain>')
WHERE path = 'design/head/includes';

For example:

UPDATE core_config_data
SET value = REPLACE(value, 'http://localhost/', '')
WHERE path = 'design/head/includes';

Then delete the cache:

rm -rf var/cache/*
  • Or read this article to change domain: fastcomet.com/tutorials/magento2/change-domain
    – MrTo-Kane
    Commented Jun 28, 2016 at 8:56
  • 1
    Yes you are right. I needed to change localhost to and it worked like a charm. Although minicart seems to be not getting updated but my cart issue have been solved. Thanks
    – Rushvi
    Commented Jun 28, 2016 at 9:00
  • In apache 2.4 you create virtual hosts, so localhost to ip won't work. Secondly in first installation of magento 2.1.8 you don't have 'design/head/includes' in core_config_data. Please update your answer to cater my request too. Commented Sep 15, 2017 at 12:07

Those who don't wish to change the localhost url and doesn't want to add vhost for this problem. Here's the quick fix.

The problem is due to form_key mismatch. The form key which gets posted during add to cart action is getting mismatched with store session form key.

Go to

vendor/magento/module-checkout/Controller/Cart/Add.php execute()

method. and comment out the first If condition.

**NOTE:**This is not a recommended solution for Production environment.

  • Please submit the standard solution also Commented Jan 10, 2018 at 13:20

I am using Mac and I faced this issue using localhost as URL for Magento 2 instances. This is a quick fix if you made a new instance and/or trying to debug something quickly...

Following this answer posted above in this thread fixed my issue.


Sounds like it could be a session based issue, are you able to log into the magento admin or a customer account?

Anything in any of the logs pointing towards the add to cart functions?

  • I am able to sign in to admin but not customer on front end. once I created customer it was showing every detail of customer now once I logged out and trying login again not working. So how to solve this session based issue. Nothing is in logs also.
    – Rushvi
    Commented Jun 28, 2016 at 7:16
  • If you clear your browser cache & cookies i should imagine it would work again but will probably stop working after the first attempt to add, you could try switching session storage to database based sessions.
    – DanCarlyon
    Commented Jun 28, 2016 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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