I'm learning Magento 2 and can see that Magento has two index.php files. One is in the root folder and another one is in Pub folder. While reading many of the posts regarding webroot of Magento, I can see that we have to set the webroot to Pub folder for security.

Currently, I have installed the Magento in Xampp.

Can anyone please tell me how to set the webroot to Pub in Magento 2?


To set webroot to pub you will have to tell Magento where the pub folder actually is with something like this

#File: pub/index.php
$params = $_SERVER;
$params[Mage::PARAM_APP_URIS][Mage_Core_Model_Dir::PUB] = '';
$entryPoint = new Mage_Core_Model_EntryPoint_Http(new Mage_Core_Model_Config_Primary(BP, $params));

You can also refer to https://alanstorm.com/magento-2-the-pub-folder/. But be ready to face some problems. You can find some of the problems you will face here https://github.com/magento/magento2/issues/15092

| improve this answer | |

You can achieve this by updating your virtual host file, you need to change DocumentRoot DocumentRoot /var/www/html/magento2ce/pub:

Example code:

<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/magento2ce/pub

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory "/var/www/html">
                    AllowOverride all


For more information refer magento 2 devdocs


| improve this answer | |

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.