1

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?

Thanks.

Sudhakar SJ
  • 71
  • 1
  • 14

2 Answers2

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

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.

 127.0.0.1  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.

1

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

bernieu2
  • 594
  • 3
  • 7