18

I have a Magento 2.0.2 installation in developer mode and I still can't figure out how to force it to regenerate the static view files whenever I make a change in my CSS.

I verified that I am in developer mode by running php bin/magento deploy:mode:show

On this page it says that developer mode disables static view files caching, but that is not the case for me.

I tried to edit the di.xml as mentionned in this solution but it didn't change Magento's behavior.

How can I tell magento to automatically regenerate static view files?

5 Answers 5

5

In developer mode, M2 does not generate static files. It should create symlinks to them from the various modules. If you however have ran setup:static-content:deploy and have those files in place, it won't update them. Try removing all static files and see if Magento links to them (be careful not to remove the actual files if you have symlinks)

6
  • 1
    I tried deleting the whole content of pub/static (without deleting the .htaccess file) and it didn't work. It looks like the old files were regenerated.
    – AlexandreC
    Commented Mar 10, 2016 at 17:28
  • Currently, the only way I'm able to get the updated content is by clicking 'Flush Static Files Cache' in the Magento Cache Management page.
    – AlexandreC
    Commented Mar 10, 2016 at 17:31
  • 6
    I had the same problem of symlinks not being generated in developer mode; then I realized I had deleted the .htacces file from pub/static; once I restored the .htaccess file in pub/static the next request regenerated all symlinks; hope it helps. Commented Mar 22, 2016 at 11:12
  • I have the same problem currently with Magento 2.0.6. Tried re-adding the .htaccess-file (I run nginx, so I didn't think it would do much), and as expected, it didn't work. Previously my symlinks were created, but now not anymore ... Commented May 25, 2016 at 9:41
  • 1
    As we thought pub/static is autogenerated anyways we also deleted it manually at one point and ran into the same problem. Looks like in our apache2/php7 setup the now missing .htaccess file is really responsible for this. After recreating the original .htaccess developer mode was working fine again. Here the link to the recent .htacces: github.com/magento/magento2/blob/develop/pub/static/.htaccess
    – Jey DWork
    Commented May 25, 2016 at 17:40
1

Same happened to me. After moving the site to another server, it turned out I didn't set the file permissions correct.

I ran find . -type d -exec chmod 770 {} \; && find . -type f -exec chmod 660 {} \; && chmod u+x bin/magento and that solved my problem.

More info: Magento 2: Recommended File Permission for shared hosting

Update: make sure the pub folder (magento/pub) and the underlying folders have read and write permissions.

1
  • 2
    Whomever downvoted: why?
    – Krista K
    Commented Jan 5, 2018 at 19:24
0

I was facing the same issue with my less updates noting showing unless I flushed my static files. The fix for me was to disable mod_expires. This was caching the css and etc.

Inside of the pub/static/.htaccess file you will should have something like the following:

<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, html
    <FilesMatch \.(css|js|html|json)$>
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType text/html "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType application/json "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>

By disabling mod_expires or commenting out the above and doing a hard refresh in your browser (Mac Users hold down Shift + Command + r) your changes should start showing each time you make them.

0

I was experiencing the same issue. I had developer mode enabled for some time, then for some reason (likely an error on my part at some point), it no longer seemed to work.

Simple solution for me was to reset the mode to developer again:

php bin/magento deploy:mode:set developer

NB: You might need to set it to default and then developer.

1
  • This also didn't help. Any other suggestions? Commented Jul 4, 2019 at 1:50
0

I just had this issue too!

It turns out in my case it was a permission issue.

cat /etc/apache2/logs/error_log | grep static

and

tail -f /etc/apache2/logs/error_log | grep static

gave me interesting info (maybe your log file might be named differently)

first I saw:

[Wed Oct 30 12:19:34.287356 2019] [core:crit] [pid 27633] (13)Permission denied: [client 24.48.87.7:16680] AH00529: /home/[datuser]/public_html/pub/static/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/home/[datuser]/public_html/pub/static/' is executable

it turned out my pub/static folder was not executable. Then after fixing that I got

[Wed Oct 30 12:22:46.490759 2019] [:error] [pid 27290] [client ipremoved] SoftException in Application.cpp:267: File "/home/[datuser]/public_html/pub/static.php" is writeable by group, referer: [url removed]
[Wed Oct 30 12:22:46.490961 2019] [core:error] [pid 27290] [client ipremoved] End of script output before headers: static.php, referer: [url removed]

On our server apache cant serve files that are writable by group for some reason, some Cpanel security stuff I believe. So I had to set 644 on all files under pub and finally my symlinks started to get created!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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