2

I had a problem with magento 2, where in localhost I created the website and everything was fine, after importing to my server the CSS and JS was not working.

I search for so many answers and still no luck, after awhile I decided to simply start again, so I imported magento to my server, installed it with no errors, but when I entered the home page the CSS and JS does not work.

Here's a couple of things I already tried:

php bin/magento setup:content-static:deploy

deleting the static folder and keep the .htacess and run

 php bin/magento setup:content-static:deploy

Replacing Symlink with Copy

Checking the folders permissions

Here is the link of my website: http://maquinasdeoutrostempos.pt/

Thanks in advance

Aasim Goriya
  • 5,444
  • 2
  • 28
  • 53
  • Please check this link which could help you https://magento.stackexchange.com/questions/154728/magento-2-not-loading-css-and-js-after-successful-installation-in-windows?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Venkatesh Mar 25 '18 at 14:21
  • @Venkatesh i tried it but still doesn't work. – Ruben Perdigao Mar 25 '18 at 14:27
  • Have you tried this "INSERT INTO 'core_config_data' ('path', 'value') VALUES ('dev/static/sign', 0) ON DUPLICATE KEY UPDATE value = 0;" in Database. – Venkatesh Mar 25 '18 at 14:31
  • @Venkatesh it says that i have a syntax error in : ('path', 'value') VALUES ('dev/static/sign', 0) ON DUPLICATE KEY UPDATE value = 0 – Ruben Perdigao Mar 25 '18 at 14:36
  • Please try this "INSERT INTO core_config_data(path, value) VALUES ('dev/static/sign', 0) ON DUPLICATE KEY UPDATE value=0;" – Venkatesh Mar 25 '18 at 14:43
  • @Venkatesh i did it, and i clear the config cache, but it still doesn't work – Ruben Perdigao Mar 25 '18 at 14:48
  • Could you check .htaccess file is present in pub/static – Venkatesh Mar 25 '18 at 14:54
  • @Venkatesh it is there – Ruben Perdigao Mar 25 '18 at 14:57
  • Could you follow the steps given in this link https://magento.stackexchange.com/questions/212514/refused-to-apply-style-because-its-mime-type-text-html-is-not-a-supported-s?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Venkatesh Mar 25 '18 at 14:58
  • @Venkatesh copied the .htacess from here: https://github.com/magento/magento2/blob/2.2-develop/pub/static/.htaccess, but still no luck – Ruben Perdigao Mar 25 '18 at 15:08
  • Are the files in the correct pub folder? you are looking to the pt_PT inside pub, but sometime during deploys Magento will only populate the en_US folder. Check that dir and if it's empty run php bin/magento setup:content-static:deploy pt_PT – circlesix Mar 25 '18 at 15:14
  • @circlesix i always deploy to pt_PT with : php bin/magento setup:content-static:deploy pt_PT, but still doesn't work. – Ruben Perdigao Mar 25 '18 at 15:19
  • @ruben, inside the pub dir, when you navigate all the way down to the files that are kicking the 404 error on the site, what do you see? and what are the file permission and ownership? – circlesix Mar 25 '18 at 19:16
  • @circlesix the permissions are 644 – Ruben Perdigao Mar 26 '18 at 16:02
  • Ok, that might be the problem. I would try getting the path to just one file in the pub folder, a css or js file. Try to hit that file with the full path in the browser. It's going to fail (we already know that from the console errors) but then changing just that file to 755. if you still can't hit it, change it to 775. and finally 777. That might be the reason these files can't be hit. – circlesix Mar 26 '18 at 16:10

4 Answers4

5

1] Check whether file permissions are given properly to all the Magento files

2] In your database run below query into "core_config_data" table and check you get any result or not

SELECT * FROM `core_config_data` WHERE `path` LIKE '%static/sign%'

3] If no then run below query

insert into core_config_data (config_id, scope, scope_id, path, value) values (null, 'default', 0, 'dev/static/sign', 0);

or

4] if "dev/static/sign" value is already exist into table set that 1 to 0

run php bin/magento c:f , php bin/magento s:s:d -f

I hope this solve your problem.

Usman Yousaf
  • 621
  • 7
  • 16
Kajal Solanki
  • 336
  • 2
  • 9
1

In my case - I missed to add the AllowOverride to apache config during install.

Add the following to the end of Apache 000-default.conf (or whatever your apache config file is):

<Directory "/var/www/html">
    AllowOverride All
</Directory>

After adding - restart apache, solved the static content not loading issue.

Paktas
  • 171
  • 1
  • 8
0
  1. Check if you have well your .htaccessin the root project location

  2. Check if you have well the css files in your current theme.

  3. Check if you have well the right permissions 755 in app/design/frontend/Magento/luma/web, app/design/frontend/Magento/luma/web/css/*.css

  4. remove the content folders of pub/static, var/cache, var/page_cache, var/view_preprocessed

  5. Launch this commands:

    • php bin/magento setup:static-content:deploy --theme Magento/luma pt_PT -f

    • php bin/magento cache:clean

    • php bin/magento cache:flush

PЯINCƎ
  • 11,669
  • 3
  • 25
  • 80
0

For me it was simply because mod_rewrite wasn't enabled.

sudo a2enmod rewrite

and

service apache2 restart

Happy Coding!

Rohit Chauhan
  • 560
  • 5
  • 17