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.

asked Mar 31, 2021 at 2:18
2
  • 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. Commented Mar 31, 2021 at 6:38

2 Answers 2

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.

answered Apr 1, 2021 at 18:32
2
  • Thanks, Sonal. Big help Commented Apr 14, 2021 at 23:16
  • You are welcome. Commented Apr 19, 2021 at 8:52
1
answered Mar 31, 2021 at 2:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.