I am running a freshly installed 10.0.9 installation that I have begun building on. I have tried to upgrade the site both using composer and manually and no matter which way I've used my site breaks after the update. What happens is that the stylesheets stop loading and I get either 503 or 404 errors pointing to sites/default/files/css or sites/default/files/js. I've made sure to do the upgrade in maintenance mode, run db updates and clear caches. The only thing I can do to fix the problem is revert to my pre-upgrade backups.

Any ideas on what I'm missing here?

Comments

drupal_rogue’s picture

I seem to have found a solution and it was a simple solution. As near as I can tell, the fix was to uncheck "Aggregate CSS Files" and "Aggregate JavaScript Files" under the "Bandwidth Optimization" section at Administration>Configuration>Development>Performance.

Cheers to all and a great day!

gisle’s picture

I see that you have fixed it by turning off css/js aggregation.

However, your root problem is that the web server does not have write access to public files (i.e. everything below sites/default/files). You should fix this, because, if you don't, having these permissions wrong is going to bite you later.

- gisle

drupal_rogue’s picture

Hello gisle

Thanks for your suggestion. I checked those directories just now and they have write permissions for the web server. I can't see a problem there. Is it possible there is  something wrong in an htaccess file some place that would cause write issues for Drupal? If I turn on css/js aggregation I see directories being created for css right away but my css doesn't seem to load. If I turn aggregation off everything is fine again and the sites/default/files/css directory is removed

gisle’s picture

I checked those directories just now and they have write permissions for the web server. I can't see a problem there.

Well, in my experience, the symptoms you describe is consistent with permission settings for public files being configured wrong. This typically occurs after the CLI is used to do an upgrade.

What is the output of this after you've turmed aggregation back on?

cd sites/default/files
ls -la

- gisle

drupal_rogue’s picture

This is a cPanel hosted server with a webhost. The output you asked for is below.

user@server [~/public_html/dev/sites/default/files]# ls -la
total 5032
drwxrwxr-x 8 cpuser cpuser    4096 Jul 16 18:05 ./
dr-xr-xr-x 3 cpuser cpuser    4096 Jul 16 15:07 ../
drwxrwxr-x 2 cpuser cpuser    4096 Jun 26 13:58 2023-06/
drwxrwxr-x 3 cpuser cpuser    4096 Jun 18 15:58 config_mNr3bB2D_BWvzeRcO4aYDmXDRfFaHuF18lg5wYtTqJK0Z-oWPm8Hqq6x5xFifoJwY4OGJpGoww/
-r--r--r-- 1 cpuser cpuser     486 Jul 16 18:05 .htaccess
-r--r--r-- 1 cpuser cpuser     486 Jun 18 15:58 .htaccess~
drwxrwxr-x 2 cpuser cpuser    4096 Jun 22 07:54 inline-images/
drwxrwxr-x 3 cpuser cpuser    4096 Jun 20 15:38 media-icons/
drwxrwxr-x 3 cpuser cpuser    4096 Jul 16 18:02 php/
drwxrwxr-x 7 cpuser cpuser    4096 Jun 26 13:57 styles/

gisle’s picture

From what I am able from learn from this line:

drwxrwxr-x 8 cpuser cpuser    4096 Jul 16 18:05 ./

the web server does not have write permission to public files – unless the web server is named "cpuser", which, frankly, is a terrible way to do configure permissions.

Not having write permission prevents it from creating the necessary directories for aggregate css and js.

The mode bits should be this:

drwxrwxrwx 8 cpuser cpuser    4096 Jul 16 18:05 ./

This should fix it:

cd sites/default/files
chmod a+w .

However, the mode bits are wrong for the subdirectories already created as well. You're not going to be able to upload images or other files, or to generate new image styles.  Normally, I would recommend doing this:

cd sites/default/files
chmod -R a+w .

However, in your case, there is a subdirectory named php in your public files directory. Making that directory writable by the web server is a very bad for security. It should not have been there (and since I don't know the history of your web site, I am no idea why it is there). I therefore cannot recommend that you do this. Just make a note that file uploads is not going to work on your site down the line, until you get this fixed in a secure way.

- gisle

drupal_rogue’s picture

Hi gisle

I did those permissions changes as you've recommended and then set the aggregate settings for css and js and the same problem persists. As another reply suggested that the database updates fixed their issue I can say that I made sure the database updates were run and as of now drush reports that there are no database updates that need applied. I'm at a loss here. Thoughts on anything else I can check?

Thanks

gisle’s picture

After turning aggregation back on, and running the chmod/command, what is the output of this:

cd sites/default/files
drush cr
ls -la

- gisle

drupal_rogue’s picture

# drush cr
 [notice] The file assets://css was not deleted because it does not exist.
 [notice] The file assets://js was not deleted because it does not exist.
 [success] Cache rebuild complete.

# ls -la
total 5032
drwxrwxrwx 8 cpuser cpuser    4096 Jul 16 18:05 ./
drwxr-xr-x 3 cpuser cpuser    4096 Jul 16 15:07 ../
drwxrwxrwx 2 cpuser cpuser    4096 Jun 26 13:58 2023-06/
drwxrwxrwx 3 cpuser cpuser    4096 Jun 18 15:58 config_mNr3bB2D_BWvzeRcO4aYDmXDRfFaHuF18lg5wYtTqJK0Z-oWPm8Hqq6x5xFifoJwY4OGJpGoww/
-rwxrwxrwx 1 cpuser cpuser     486 Jul 16 18:05 .htaccess*
-rwxrwxrwx 1 cpuser cpuser     486 Jun 18 15:58 .htaccess~*
drwxrwxrwx 2 cpuser cpuser    4096 Jun 22 07:54 inline-images/
drwxrwxrwx 3 cpuser cpuser    4096 Jun 20 15:38 media-icons/
drwxrwxr-x 2 cpuser cpuser    4096 Jul 18 10:22 php/
drwxrwxrwx 7 cpuser cpuser    4096 Jun 26 13:57 styles/

drupal_rogue’s picture

One thing I found strange is that this problem only presented itself after trying to update from 10.0.9. I did it manually by copying files few times and by using composer. In all cases I had to revert to backups to restore functionality. After turning off css aggregation it was working after the update.

gisle’s picture

The missing directories now should be automatically re-created and populated when they are required (i.e. css/js aggregation should now work as expected. However, this output from drush indicates that they're not re-created when you refresh the front page.

 [notice] The file assets://css was not deleted because it does not exist.
 [notice] The file assets://js was not deleted because it does not exist.

I have no explanation for why this is so. I am sorry, but I can't think of anyhing else.

- gisle

drupal_rogue’s picture

When I turn CSS aggregation on that directory gets created. For some reason the files that are being asked for are inaccessible. And further, for some reason it was only after the update. The best thing I can think to do to try to solve this mystery is to spin up backups of 10.0.9 on another directory and try to find any differences in permissions and .htaccess files that might account for this. If I do find something I'll update here.

gisle’s picture

When I turn CSS aggregation on that directory gets created. For some reason the files that are being asked for are inaccessible.

I still believe that this must be related to botched file system permission settings. What is the output after you've turned css aggregation on and refreshed the front page when you type the following:

cd sites/default/files
ls -la
cd css
ls -la

- gisle

jeyro’s picture

Same problem. Css goes missing. In our case, css comes back after the database update.

drupal_rogue’s picture

I did make sure the database update was run but that didn't resolve my issue unfortunately.

gisle’s picture

The public file system mode bits and the MySQL database are two very different things. IMHO, the problems reported by the OP is not in any way database related. They may be cache related.

- gisle

tolstoydotcom’s picture

There's more in file permissions here: https://www.drupal.org/docs/administering-a-drupal-site/security-in-drup...

If you manually put a CSS file in the styles directory, can you load it in the browser?

Is some other process editing your .htaccess file?

Are files being written to the styles directory when you enable aggregation? If not, are there error messages at admin/reports/dblog?

Available for paid support, module development, migrations, consulting...

sseto’s picture

You guys ever find how to fix this issue? Rebuilding the cache never updates my JS or CSS changes. I tried deleting CSS and JS directories and rebuilding them, but it's not working...weird.

westsonoma’s picture

Final edit, I hope.  I finally got aggregation to work reliably by making the the "optimized" directory, where aggregated files are stored, owned by the web server.  Same for all files and directories below "optimized".  Previously the web server had full read/write/execute permissions, but only at the group level. 

I'm still using these settings in the settings.php file:

$settings['file_assets_path'] = 'sites/mysite/files/optimized';
$settings['file_public_path'] = 'sites/mysite/files';

Edited to add:  a couple of days after I wrote this, I'm back to JavaScript aggregation not working, regardless of what's in the settings.php file.  CSS is still fine.  Turning off aggregation gets JavaScript back.

Aggregation of both CSS and JavaScript worked fine on a new install of Drupal 10.1.2 until I set the file_assets_path and file_public_path in settings.php.  After that, JavaScript aggregation stopped working, although CSS was fine. 

The values I used were:

$settings['file_assets_path'] = 'sites/mysite/files/optimized';
$settings['file_public_path'] = 'sites/mysite/files';

With these settings, I could get JavaScript to work again only by unchecking the 'Aggregate JavaScript files' checkbox.

I removed both settings to let them default, and JS aggregation once again started working.  I put back only $settings['file_assets_path'], and JS is still working, and the aggregated JS and CSS files are now under the 'optimized' directory. 

It seems likely I don't understand what $settings['file_public_path'] is meant to do.  If you're experiencing this problem, you might want to play with these settings.

drupal_rogue’s picture

Hi, I did find that in maintenance mode the caches weren't rebuilding so if I tried to load my maintenance page just to "test things out" all the stylesheet data was not cached. Once I take it out of maintenance mode everything worked again.

elaine.ong’s picture

Site broken after update to 10.1.4 due to security patch.

Need help. Tia.

kerby70’s picture

#3370828: Ensure that edge caches are busted on deployments for css/js aggregates

Since Drupal 10.1 aggregated assets are no longer updated on cache rebuild. That affects the traditional deployment workrflow. Developers must always bumb library versions before committing changes in CSS/JS files. This change is not documented in the corresponding change record.

phl3tch’s picture

Both sites were recently migrated from D9 to 10.1.5. Works with aggregation turned off, fails with it turned on. Failure appears on both my development environment and production. My local files directory permissions are wide open. If I manually create a css and js folder, Drupal deletes them, so I know it is able to access the files directory. Can't say I understand #comment-15267804 -- doesn't seem to be directly related and anyway that was patched a month ago, unless the patch has not yet made its way into a release. No errors being logged by Drupal or the web server. Nothing in the console either. Both admin theme and front end theme are failing. 

Just a moment ago I tested it again and inexplicably the admin theme started aggregating, but the front end theme still did not. Cleared caches and now they're both broken again. 

phl3tch’s picture

Turned aggregation off and back on using drush instead of the GUI and now it works fine. Go figure. 

mattau’s picture

How do you enable/disable with drush?

Edit: Never mind. Found the answer.

Also it looks like my particular issue was related to Redirect.

matthewv789’s picture

If I manually create a css and js folder, Drupal deletes them, so I know it is able to access the files directory.

Yes, this.

oligerd’s picture

I've added to the settings.php
 

$settings['file_assets_path'] = 'sites/default/files/styles';

and it works for me on the Pantheon and on the platform.sh as well.

And no need to change Nginx config.

Update:
In my case it was a fast_404 module issue - Fast404 prevents css/js assets from generating when aggregation is enabled on Drupal 10.1
https://www.drupal.org/project/fast_404/issues/3373845
So, the patch fixed the issue.

dmitrii puiandaikin’s picture

Thanks, got the same issue

mohithasmukh’s picture

Hi, 

I am still seeing issues with my css and js even though I do not have 404 fast module enabled. 

I have added the code to the settings.php file but seems to do nothing. I am on drupal 10.1.6.

Thanks.

xiukun.zhou’s picture

Thanks, 

upgrade fast_404 to 3.2 fixed it.

composer require 'drupal/fast_404:^3.2'

xiukun

mahesh.umarane’s picture

Hi,

I have upgraded the fast_404 module to 3.2 but still the issue is not resolved. Any other things can be tried?

bwaindwain’s picture

Is your server running nginx and php-fpm? See nginx config suggestions at: https://www.drupal.org/node/2888767

scottholmes’s picture

After clearing cache with drush (drush cr) or even with the gui the directories default/files/styles/css and js revert back to www-data ownership from my desired ownership.  chown allows me to drush cr again, but ownership changes back again.

marvs5’s picture

I've had this issue on all of my >=10.1 sites, either through upgrade or new install.  Here's what I did to finally fix this problem in case it can help others.  I run Nginx, so this solution is only for Nginx servers.

1. Change 

location ~ ^/sites/.*/files/styles/ {

to

location ~ ^/sites/.*/files/(css|js|styles)/ {

2.  Remove this code if you have this anywhere in your settings

location ~* \.(js|css)$ {
	expires 2d;
	add_header Cache-Control "public, no-transform";
}

You can then turn on CSS and js aggregation and the site will display properly.

kushsakshi’s picture

I am also facing this issue in my production site and tried everything which is suggested in this query list. still no luck

My changes are showing in admin login, not showing for  anonymous user or out side the login.