I am have installed Magento 2.4 successfully. I don't know why it's loading from the pub folder, not the root folder. I have followed all the document still not working.

The links I have followed https://firebearstudio.com/blog/magento-2-css-and-javascript-files-are-not-loading.html, Magento 2 CSS and JavaScript not loading from correct folder.

Still no USE. CSS and Javascript file even admin URL also not loading. Can anyone help to fix it?


  • Did you check my answer which I mention? Commented Mar 31, 2021 at 3:43
  • Magento 2.4.2 now loads by default from the magento_root/pub folder.
    – paj
    Commented Mar 31, 2021 at 6:38

2 Answers 2


Step 1: -

We need to set document root to pub, to do this go to file C:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/magento2/pub"
    ServerName yourname.magento.com

paste this code at the bottom of the file.

yourname.magento.com - this is domain name which you set as per your wish. So now you need to access magento frontend and admin with base url "yourname.magento.com".

Step 2:-

Now lets edit C:\Windows\System32\drivers\etc\hosts file and add the below line at the bottom of the file.  yourname.magento.com

Step 3: - Update the base URL:

Go to our magento database and run below command

  UPDATE core_config_data SET value='http://yourname.magento.com/' WHERE path='web/unsecure/base_url';

Step 4:- Update the app/etc/env.php file

The following node needs to be appended to the env.php file.

'directories' => [
    'document_root_is_pub' => true

Step 5 : - Switch to developer mode.

php bin/magento deploy:mode:set developer
php bin/magento cache:flush

Now check your frontend and backend.

  • Thanks, Sonal. Big help
    – jackcar
    Commented Apr 14, 2021 at 23:16
  • You are welcome. Commented Apr 19, 2021 at 8:52

It should be loaded from pub for security. Webserver doc root should be changed to pub.

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

or similar topics:

Magento 2.4.2 Window10 localhost Xampp 404 not found

404 Not Found after fresh Magento 2.4.2 installation

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.