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.
-
Did you check my answer which I mention?Rohan Hapani– Rohan Hapani2021年03月31日 03:43:04 +00:00Commented Mar 31, 2021 at 3:43
-
Magento 2.4.2 now loads by default from the magento_root/pub folder.paj– paj2021年03月31日 06:38:48 +00:00Commented 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
</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.
-
Thanks, Sonal. Big helpjackcar– jackcar2021年04月14日 23:16:47 +00:00Commented Apr 14, 2021 at 23:16
-
You are welcome.Sonal- TheCoachSMB– Sonal- TheCoachSMB2021年04月19日 08:52:21 +00:00Commented 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: