15

I'm trying to figure out how Magento 2 is working. I've seen something that made me confuse.

Magento 2 have 2 possible root folder:

/path/to/magento2/index.php
/path/to/magento2/pub/index.php

One is at the absolute top level of Magento 2’s distribution folder. The second is inside the “pub” folder.

If I set base URL is either of them, magento is working perfectly.

Can anyone explain me why Magento 2 using 2 root folder like that ?

1
  • i like when root folder is /pub/
    – MagenX
    Jan 22, 2016 at 17:09

3 Answers 3

32

Using /pub is better, because it is more secure. Why? Because in that case most of Magento's code will live outside the public document root, so the possible attack surface is smaller. In other words, when you use the top level folder as document root, you have to make sure that various folders (such as app) are explicitly denied in your webserver configuration.

That said, not everybody can configure the document root, so Magento provided a top level index.php for compatibility.

1
  • Best answer short explained. +1 Jan 22, 2016 at 19:48
1

Main reason that no all Magento Users can configure webroot to the "pub" directory. And of course due to backward compatibility.

0

If you want to use /pub folder as root be ready to have a problems with robots.txt and sitemap.xml.

More info: https://github.com/magento/magento2/issues/1146

Your Answer

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

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