How to Modify the Magento 2 Root Directory?

  • /pub/
  • /setup/
  • /var/
  • Other folders
  • The Magento app is served from /var/www/html/magento2/pub. The rest of the Magento file system is vulnerable because it is accessible visa a browser. Setting the webroot to the pub/directory prevents visitors from using their browsers to access sensitive portions of the Magento file system.
    We will teach you exactly how to modify the Magento 2 root directory and serve files from the /pub/folder in the sections below:

    STEP-BY-STEP PROCESS TO MODIFY THE MAGENTO 2 ROOT DIRECTORY

    Please follow the below steps to learn how to modify the Magento 2 root directory.

    STEP 1: First of all, you must to edit the server config.

    1. Go to your Magento 2 server and log in.
    2. Edit the virtual host file.

vim /etc/apache2/sites-available/000-default.conf

3. Now, you need to add the path to /pub/folder to the document root directive.
I wish you success in your business and a significant increase in sales!