1

CSS AND JS NOT WORKING

I tried every possible solution on this forum and nothing works:

php bin/magento setup:upgrade
php bin/magento cache:clean
php bin/magento setup:static-content:deploy 

core_config_data dev/static/sign to 0

chmod -R 777 var/* pub/*
chown -R user:webgroup pub/static

app/etc/di.xml
Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
Magento\Framework\App\View\Asset\MaterializationStrategy\Copy

rewrite_mod enable

1) Set Magento 2 developer mode.

sudo php bin/magento deploy:mode:set developer
2) Remove Static Content for adminhtml.

sudo rm -rf pub/static/adminhtml/*
3) try forced Content Deploy

sudo php bin/magento setup:static-content:deploy -f
4) Give permission to pub, var, generated

sudo chmod -Rv 777 pub var generated

I deleted also the cache, the static/* , put the .htaccess from pub folder, I tried everything so please somebody help me with this nightmare.

Magento is for make everything easier but I totally disagree, since I use magento everything is more complex and always something is failing.

1

If solutions above doesn't help you - try to check file owner for your static files.

This error is usually occur, when you run console commands from root user instead of magento web user.

Try to run this command sudo chown -R webuser:webusergroup pub/static where webuser:webusergroup - this is user of your web server

  • Is the first thing that i did after get the error, not working, but thanks – Javier Teodoro Diaz Dec 21 '18 at 18:23
0

You Can try the process described below.

1) Set Magento 2 developer mode.

sudo php bin/magento deploy:mode:set developer

2) Remove Static Content for adminhtml.

sudo rm -rf pub/static/adminhtml/*

3) try forced Content Deploy

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

4) Give permission to pub, var, generated

sudo chmod -Rv 777 pub var generated
  • Thanks for the answer, I tried that solution multiples times and is not working either – Javier Teodoro Diaz Dec 21 '18 at 16:31
0

Don't copy the .htaccess from pub folder or from any other folder to static, you need to copy only .htaccess from static folder. If you don't have the .htaccess of static then copy it from either another installation or use the following .htaccess:

<IfModule mod_php5.c>
php_flag engine 0
</IfModule>

<IfModule mod_php7.c>
php_flag engine 0
</IfModule>

# To avoid situation when web server automatically adds extension to path
Options -MultiViews

<IfModule mod_rewrite.c>
    RewriteEngine On

    ## you can put here your pub/static folder path relative to web root
    #RewriteBase /magento/pub/static/

    # Remove signature of the static files that is used to overcome the browser cache
    RewriteRule ^version.+?/(.+)$ $1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteRule .* ../static.php?resource=$0 [L]
    # Detects if moxieplayer request with uri params and redirects to uri without params
    <Files moxieplayer.swf>
        RewriteCond %{QUERY_STRING} !^$
        RewriteRule ^(.*)$ %{REQUEST_URI}? [R=301,L]
    </Files>
</IfModule>

############################################
## setting MIME types

# JavaScript
AddType application/javascript js jsonp
AddType application/json json

# CSS
AddType text/css css

# Images and icons
AddType image/x-icon ico
AddType image/gif gif
AddType image/png png
AddType image/jpeg jpg
AddType image/jpeg jpeg

# SVG
AddType image/svg+xml svg

# Fonts
AddType application/vnd.ms-fontobject eot
AddType application/x-font-ttf ttf
AddType application/x-font-otf otf
AddType application/x-font-woff woff
AddType application/font-woff2 woff2

# Flash
AddType application/x-shockwave-flash swf

# Archives and exports
AddType application/zip gzip
AddType application/x-gzip gz gzip
AddType application/x-bzip2 bz2
AddType text/csv csv
AddType application/xml xml

<IfModule mod_headers.c>

    <FilesMatch .*\.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$>
        Header append Cache-Control public
    </FilesMatch>

    <FilesMatch .*\.(zip|gz|gzip|bz2|csv|xml)$>
        Header append Cache-Control no-store
    </FilesMatch>

</IfModule>

<IfModule mod_expires.c>

############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires

    ExpiresActive On

    # Data
    <FilesMatch \.(zip|gz|gzip|bz2|csv|xml)$>
        ExpiresDefault "access plus 0 seconds"
    </FilesMatch>
    ExpiresByType text/xml "access plus 0 seconds"
    ExpiresByType text/csv "access plus 0 seconds"
    ExpiresByType application/json "access plus 0 seconds"
    ExpiresByType application/zip "access plus 0 seconds"
    ExpiresByType application/x-gzip "access plus 0 seconds"
    ExpiresByType application/x-bzip2 "access plus 0 seconds"

    # CSS, JavaScript
    <FilesMatch \.(css|js)$>
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"

    # Favicon, images, flash
    <FilesMatch \.(ico|gif|png|jpg|jpeg|swf|svg)$>
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"

    # Fonts
    <FilesMatch \.(eot|ttf|otf|svg|woff|woff2)$>
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
    ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
    ExpiresByType application/x-font-ttf "access plus 1 year"
    ExpiresByType application/x-font-otf "access plus 1 year"
    ExpiresByType application/x-font-woff "access plus 1 year"
    ExpiresByType application/font-woff2 "access plus 1 year"

</IfModule>

Above .htaccess is for 2.1.16. If this is not a correct version or its not working for you then you can download the correct version magento2.1 and copy the .htaccess from magento_root/pub/static to your magento2 installation.

  • Thanks for the answer, unfortunately I tried with this solution but still not working – Javier Teodoro Diaz Dec 21 '18 at 16:30
0

Please try the process described below. Modify the app/etc/di.xml file by changing the following content:

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

To:

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

RUN BELOW COMMAND:

php bin/magento setup:static-content:deploy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.