Magento 2 not loading CSS and JavaScript
Asked Answered
F

26

11

I have installed magento 2 successfully on localhost but I am not able to see admin panel as it render 404 error to me.

Secondly, When I open front-end then CSS and JavaScript is not loading.They also renders 404 errors.

Also When I try to run command:

{your Magento install dir}/bin/magento setup:static-content:deploy

I got the following error

[InvalidArgumentException]                                              
There are no commands defined in the "setup:static-content" namespace.
Funch answered 2/12, 2015 at 10:33 Comment(1)
Refer this #30493338Shewmaker
A
19

This One Worked for Me. use this Command php bin/magento setup:static-content:deploy

Step 1 : In CMD Open your root directory using cd command

Step 2 : php bin/magento setup:static-content:deploy - run this Command

then,Check Your pub/static folder, CSS and Js files will be available there

Refer this

Attainment answered 2/12, 2015 at 12:20 Comment(1)
Hi, I have the same problem and when i follow your istruction at step 2 I get: "Magento supports PHP 5.5.0 or later. Please read devdocs.magento.com/guides/v1.0/install-gde/…" BUT i have PHP 5.5.27 on my server!!! Somebody can help me?Chaumont
P
17

Here is the simplest solution if showing version name in css path

like : pub/static/version323334/

then run this query in my sql

 INSERT INTO core_config_data (path, value) 
VALUES ('dev/static/sign', 0) 
ON DUPLICATE KEY UPDATE value = 0;

after that clear the config cache

 bin/magento cache:clean config

you can also disable static file version form admin

enter image description here

Prescriptible answered 15/7, 2017 at 5:28 Comment(4)
This one resolved the issue of github.com/magento/magento2/issues/21201. After this may need to perform sudo rm -rf pub/static sudo rm -rf var/cache sudo rm -rf var/composer_home sudo rm -rf var/generation sudo rm -rf var/page_cache sudo rm -rf var/view_preprocessed sudo php -f bin/magento setup:static-content:deployLavettelavigne
Your answer is more easy to follow and it works!Agamic
Yesssss it's work for me Thanks !!!Malcolmmalcom
Perfect solution for version based problem :)Transport
S
6

Try the same command as root user by adding sudo like below

sudo php bin/magento setup:static-content:deploy
Sesame answered 25/4, 2016 at 6:0 Comment(0)
G
3

Though it is old question, its answers could not help me to fix my issue what would generate same error message. I suggest the followings:

  1. At first, you can find its underlying cause. In your magento2 directory, find magento error as follows:

tail var/log/system.log

Or find if there is any error in php error log file

If you find isolated error, fix it.

  1. If no error is found, do the followings. Remove generate folder by executing the following commands:
sudo rm -rf pub/static
sudo rm -rf var/cache
sudo rm -rf var/composer_home
sudo rm -rf var/generation
sudo rm -rf var/page_cache
sudo rm -rf var/view_preprocessed

After deleting them, you can re-create them by executing the following commands:

sudo php bin/magento setup:static-content:deploy -f
Giraffe answered 20/7, 2016 at 9:15 Comment(0)
C
3

Changing dev/static/sign to 0 in core config data worked for me

then,

bin/magento cache:flush

then,

php bin/magento setup:static-content:deploy -f
Ceylon answered 28/3, 2019 at 14:56 Comment(0)
H
2

We also faced this issue once, and sorted it out. For this you need to go directly in bin directory and use that command. For example,

php magento setup:static-content:deploy

Some times if you run this command outside of bin or from any directory

php bin/magento setup:static-content:deploy

then you will get error like (may be it is because of linux system),

[InvalidArgumentException]
  There are no commands defined in the "setup:static-content" namespace.

Update:

If any *.xml file in our custom modules is not valid then the same error will come.

Hetzel answered 2/2, 2016 at 12:39 Comment(0)
S
1

I also had same issue and below step solves my issue:

Step 1: Navigate to directory where magento is installed.
Step 2: Run "sudo php bin/magento setup:static-content:deploy"

Shields answered 12/12, 2015 at 12:0 Comment(1)
This worked for me, as there were apparently permission issues with /pub/Honorine
P
1

Provide static deploy command like this:

php bin/magento setup:static-content:deploy

Please set full permission for pub and var folders.

Patterman answered 8/2, 2016 at 9:0 Comment(0)
E
1

Run the following commands in CLI interface of your Magento2 root folder:

$ php bin/magento setup:static-content:deploy
$ php bin/magento indexer:reindex

Then delete var folder by this command at your root of magento2.

$ rm -rf var/*

Then refresh your homepage and admin panel.

Electroacoustics answered 2/2, 2017 at 13:41 Comment(0)
V
1

If you are facing theming issue after Installation in Magento 2. You can follow these steps :

  1. Run this query:

    INSERT INTO core_config_data (path, value) VALUES ('dev/static/sign', 0) ON DUPLICATE KEY UPDATE value = 0;

  2. For local machine run this query:

    UPDATE core_config_data SET value = '0' WHERE core_config_data.path LIKE '%web/seo/use_rewrites%';

  3. Remove all the files from pub and var directory:

    sudo rm -rf var/di var/generation/ var/page_cache/ var/cache/ pub/static/frontend/ pub/static/adminhtml/ pub/static/_requirejs/ pub/static/deployed_version.txt

  4. Give Permission to var and pub directories of your project:

    sudo chmod -R 777 var/* pub/*

  5. Upgrade Setup:

    sudo bin/magento setup:upgrade

  6. Deploy content:

    sudo php bin/magento setup:static-content:deploy

After these steps, you will be able to see proper theme.

Valerivaleria answered 25/6, 2018 at 16:15 Comment(0)
W
1

After trying all the solutions mentioned over here and in https://magento.stackexchange.com/questions/97209/magento-2-css-and-javascript-not-loading-from-correct-folder

We were not able to get this thing going.

But this is very weird answer but it worked for us.

Firstly, We cleared the cache and ensured that the static files are being created inside pub/static/ folder. Then checked the deployed_version.txt contains same version number as being loaded in the URL.

Our main culprit was the .htaccess file which was present in pub folder. There should be just one .htaccess file inside pub/static folder but not in pub folder. This did the trick for us after searching everywhere.

Hope it helps others looking for the similar answer.

Wellborn answered 5/10, 2018 at 3:47 Comment(1)
Yes! After two hours of debugging this issue you finally fixed it.Pedagogy
E
0

If you facing problem of css and design after installation in Windows, follow these steps

  1. php bin/magento setup:static-content:deploy
  2. php bin/magento indexer:reindex
  3. make sure apache "rewrite_module" is enable and then restart the server
  4. delete cache folder under var/cache
Exacting answered 9/1, 2016 at 17:32 Comment(0)
M
0

you just need to run this command on your Terminal

php bin/magento setup:static-content:deploy

Make sure you give the the root path of your magento in terminal and then run the above command

Meristic answered 21/1, 2016 at 12:26 Comment(0)
O
0

Just Open the

MAGENTO_ROOT/app/etc/di.xml

and replace below code form line number 574

<item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item>

TO

<item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>

DELETE

MAGENTO_ROOT/pub/static/_requirejs

MAGENTO_ROOT/pub/static/adminhtml

MAGENTO_ROOT/pub/static/frontend

Ordination answered 22/1, 2016 at 5:43 Comment(0)
V
0

Just simple and right solution, hope usefull.

Go to your wampserver icon and click on it and than

  1. Apache->apache modules->rewrite_module[enable this]

After this re-start all services and check it .

Vandyke answered 2/2, 2016 at 18:5 Comment(0)
S
0

The following answer works for me, thanks:

open file MAGENTO_ROOT/app/etc/di.xml

and replace below code form line number 574

Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink

with

Magento\Framework\App\View\Asset\MaterializationStrategy\Copy

DELETE

MAGENTO_ROOT/pub/static/_requirejs

MAGENTO_ROOT/pub/static/adminhtml

MAGENTO_ROOT/pub/static/frontend
Scarlettscarp answered 3/2, 2016 at 6:5 Comment(0)
P
0

This error happens when you have not setup permission correctly. It can't see that the command actually exist.

Try running:

sudo find . -type d -exec chmod 770 {} \; && sudo find . -type f -exec chmod 660 {} \; && sudo chmod u+x bin/magento sudo chown -R $(whoami):www-data .

Change www-data to appropriate webserver user. e.g. apache or www-data.

Paregoric answered 19/2, 2016 at 9:17 Comment(0)
C
0

This worked for me:

1) Static content deploy. Run the below command from Magento 2 root directory:

sudo php bin/magento setup:static-content:deploy

2) Clear everything in var/cache directory or flush the Magento 2 cache using the below command:

php bin/magento cache:flush

3) Set proper permissions for Magento 2 directories by executing the below command from Magento 2 root directory:

sudo find . -type d -exec chmod 770 {} \; && sudo find . -type f -exec chmod 660 {} \; && sudo chmod u+x bin/magento

Hope this helps.

Chavis answered 17/3, 2016 at 9:7 Comment(1)
It says "Access forbidden! Error 403"Filide
E
0

I just do

rm -rf var/di

then it works again.

Escaut answered 14/4, 2016 at 10:2 Comment(0)
E
0

Usually this happens because of failed compilation in the var/di folder. You can solve it by deleting everything in your var folder.

Also for future, don't forget that magento command line implements symfony verbosity levels: append --v or ---v to your command to see the exact error.

Expiate answered 15/4, 2016 at 9:27 Comment(0)
V
0

Please follow the steps below to get rid of this issues.

1) Download the Magento 2.

2) Extract this in your www OR htdocs directory.

3) Install the magento. Do not use localhost, use 127.0.0.1 in store url and admin url.

4) After successful installation DO NOT RUN MAGENTO.

5) Now delete the cache / session of magento 2. Go to the below mentioned paths and delete the files.

Magento Root > var > cache > Delete all files

Magento Root > var > page_cache > Delete all files

Magento Root > var > session > Delete all files

6) Change the behavior of symlinks for some static resources as mentioned below:-

When Magento 2 is not in production mode, it will try to create symlinks for some static resources on local server. We have to change that behavior of Magento 2 by going to edit ROOT > app > etc > di.xml file. Open up di.xml in your favorite code editor, find the virtualType name="developerMaterialization" section. In that section below, you will find an item <item name="view_preprocessed" xsi:type="object"> which needs to be modified. You can modify it by changing the following content:

Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink

To:

Magento\Framework\App\View\Asset\MaterializationStrategy\Copy

7) Delete all the files except .htaccess

Magento Root > pub > static > Delete all files except **.htaccess**

ITS DONE. Now you may run the magento Front and Backend URL

Vladamir answered 2/6, 2016 at 8:11 Comment(0)
C
0

below Solution worked: Please un below query in database. INSERT INTO core_config_data (path, value) VALUES ('dev/static/sign', 0) ON DUPLICATE KEY UPDATE value = 0; https://magento.stackexchange.com/questions/97209/magento-2-css-and-javascript-not-loading-from-correct-folder

Chapiter answered 9/1, 2020 at 10:23 Comment(0)
D
0

if you have tried php bin/magento setup:static-content:deploy or any such related commands and the issue is still there. Then you may like to try this.

This fix addresses No Css and Javascript and Admin 404 page issues after magento installation (v2.3).

step 1 : open httpd.conf.

step 2 : search for

  1. AllowOverride (may be written as AllowOverride all)
  2. Require (may be written as Require local)

in directory section of this file.

step 3 : Change

  1. AllowOverride to AllowOverride All
  2. Require to Require All Granted
Doublure answered 10/12, 2020 at 13:11 Comment(0)
D
0

I've faced the same issue and i get it resolved using the following procedure.

php bin/magento setup:static-content:deploy
php bin/magento c:f
sudo chmod -R 777 var/ pub/ generated/
sudo chown -r your-website-user:your-website-group
ln -s static pub/static
ln -s media pub/media
Desulphurize answered 8/8, 2022 at 14:20 Comment(0)
G
0

If all of the above is not working try to set 0 in the below paths in core_config_data table

web/secure/use_in_frontend

web/secure/use_in_adminhtml

Grouty answered 2/1, 2023 at 17:2 Comment(0)
S
-1

If you are facing problem of css and js page load design after installation in magento2

please follow the following step-:

open the terminal and navigate to magento web root

 $ cd /var/www/html/magento2 

Step 1.

 $ php bin/magento setup:static-content:deploy

Step 2.

 $ php bin/magento indexer:reindex

Step 3.

make sure apache “rewrite_module” is enable and then restart the server

Step 4.

 $ chown -R www-data:www-data /var/www/html/magento2 

Step 5.

 $ chmod -R 777 /var/www/html/magento2 

Step 6.

delete cache folder under var/cache

The above step working. I hope this will work for you also.

Let me know if any issue. :)

Schizoid answered 6/4, 2016 at 5:55 Comment(1)
Your assuming that their web server runs under www-data. Setting all files to full access is a security issue.Barleycorn

© 2022 - 2025 — McMap. All rights reserved.