Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento 2 not loading CSS and JavaScript

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.
like image 317
Scott Avatar asked Dec 02 '15 10:12

Scott


5 Answers

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

like image 168
Surendra Kumar Ahir Avatar answered Nov 04 '22 23:11

Surendra Kumar Ahir


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

like image 27
Mohammed Anis Avatar answered Nov 05 '22 00:11

Mohammed Anis


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

sudo php bin/magento setup:static-content:deploy
like image 6
SIBHI S Avatar answered Nov 04 '22 23:11

SIBHI S


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
like image 3
Philip Drury Avatar answered Nov 05 '22 01:11

Philip Drury


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
like image 3
Wasim Avatar answered Nov 05 '22 00:11

Wasim