6

If I try and clear my drupal site's cache using drush cc all command - the command completes successfully but when I pull up my drupal site in a browser its a mangled mess because there is no CSS.

Whereas if I sign into my site as an admin go to "Flush All Caches" my site works just fine.

This is discussed briefly here: http://dnotes.net/blog/dark-side-drop/david/why-all-my-css-gone-drush-cc

Although I don't really see a solution.

I think the underlying issue is that drush cc all isn't re-creating LESS CSS files but the "Flush All Caches" is? Is there some way I can make drush re-create the LESS files after a cache clear?

Thanks Brad

  • If drush cc works different from the one from GUI, it's drush bug and should be reported to it's issue queue, not here. – Mołot May 28 '13 at 12:33
16

Clearing cache via the UI and via drush both end up calling drupal_flush_all_caches(), but there is a subtle difference.

When you run from the UI, the PHP executes as Apache (or however you have your webserver configured). When you run from drush, it runs as the user who executed the command.

The problem in your case is that the LESS module will run its cron functions, which clears out the less directories in sites/default/files and makes a new one. When this happens, there is often a permission problem: your drush user owns the less directory and Apache can't write to it. Therefore, your CSS files don't get regenerated and your site end up unstyled.

My solution is to make sure my drush user is also in the Apache group on my server, and that my sites/default/files directory has 2775 permission on it and with ownership by apache:apache. I also make sure that the umask of httpd makes things group writable.

This makes sure that any files and directories that get created always have group ownership by apache, and that Apache can write to any directories that get made, regardless of whether it was done by httpd or from the command line.

EDIT:

There is one more difference that is worth noting. When you clear with drush, you just clear the caches. When you clear from the UI, you clear the caches and then the page reloads. When the page reloads from a cold cache, the parts used to rebuild that page get cached again. This includes making CSS files from the LESS sources.

  • Excactly the answer I had in mind. This is one of the reasons I switched from LESS to SASS. – marcvangend May 28 '13 at 13:46
  • When I'm running drush I'm running as root - so I should have complete permissions. Now I suppose its possible apache doesn't have permission to clear the less directory? I'll have to confirm that. – Brad May 29 '13 at 12:54
  • With regards to clearing via a browser re-creating the CSS and LESS sources - shouldn't that happen the first time I hit the site? In other words how is using my browser to clear cache different then using drush to clear cache and then using my browser to hit the site? If hitting the site with a cold cache re-creates less files then visiting the site after a drush cache clear should do the same thing? – Brad May 29 '13 at 12:55
  • Let me ask this - is there some way from drush to force the less files to be re-generated? For example if I did a drush cc all then I follow that with a drush regenerate-less? (I just made that last command up - but I'm asking if there is something like this). I haven't found anything but wasn't sure if I'm missing something. – Brad May 29 '13 at 12:56
  • @Brad, if you run as drush root, then root will own the less directory. Depending on your configuration, Apache may not be able to write to that directory. I ran into this same issue a little while ago, and starting setting the permission I describe as a result. – mpdonadio May 29 '13 at 12:56
1

You could use the 3.0 branch, currently 7.x-3.0-rc1.

The 3.0 version through Drush only deletes directories on cache clear, and does not recreate them, thus avoiding the issue of Drush running under a different user as the web server.

Directories are created on demand by the LESS module, so only when a user requests a page through the web server, so the directories are created under the web server user.

A full 7.x-3.0 release will be coming out as soon (hopefully this week).

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.