Question

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?

No correct solution

OTHER TIPS

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

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
        </Directory>

</VirtualHost>

For more information refer magento 2 devdocs

https://devdocs.magento.com/guides/v2.3/install-gde/tutorials/change-docroot-to-pub.html

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top