In a new install of Drupal 9.1.8 on Debian 10 running PHP 7.3 the media module is not producing image thumbnails or directory structure to hold the image styles. I had this problem on an active site that I upgraded from Drupal 8, but then created a brand new site with the same issue. I have ruled out permission errors by setting all files and folders to 777.

To reproduce: Install a new Drupal 9 site using 'composer drupal/recommended-project', enable media and media library modules, go to /media/add/image and browse to upload an image. Immediately I noticed a blank box where the image should be. After saving the media entity, the image thumbnail is still not showing. Inspecting the folder structure sites/default/files/styles exists, but nothing beyond it and no media style image. The original image was successfully created. Strangely there are no errors in the Drupal log and I could not find related errors in the Apache log file.

Perhaps it is some very specific issue with my setup, but it is pretty standard.

Comments

desierto created an issue. See original summary.

cilefen’s picture

Category: Bug report » Support request
Issue tags: -media library +Bug Smash Initiative

Hello @desierto,

I just followed those reproduction steps yet I can't reproduce this one. Yes, it sounds like something with your setup. What are the details? Are you certain the platform meets the Drupal 9 requirements?

desierto’s picture

Thanks. My machine and software definitely meet all requirements... very fast machine running the latest Debian 10 with all of the standard LAMP software... Apache 2.4, MariaDB 10.3.27, PHP 7.3.27. All's green on the Drupal Status page, including GD Image Toolkit. I haven't actually done much to the Debian install except security tightening. It seems it must have to do specifically with the process of generating the Image Styles, since it uploads the original image no problem. I have not changed any settings on the fresh install. The strangest part is it acts like everything is working with no errors and even makes the link appropriate link to the non-existent directory structure and image. Strange... I'll report back here when/if I figure it out.

cilefen’s picture

This could possibly be #3116611: Add a requirements check for GD support of allowed image types because it could just be warnings.

desierto’s picture

Thanks for your suggestions. I was hoping GD support for jpg that was the issue, so it would at least be a known quantity. It was not, although at least I'll know to look out for it moving to PHP 7.4.

My simple issue was that mod_rewrite wasn't enabled. I am surprised that it isn't something that generates a warning, or at least info suggesting it be enabled on the Drupal status page. Also this issue didn't generate any errors in the Drupal log, in fact it says creating the media was successful.

My fix:
sudo a2enmod rewrite
sudo service apache2 restart

I hope this can help someone else.

desierto’s picture

Title: Media module not creating thumbnails and directory structure » Drupal not generating image style thumbnails and associated directory structure
Status: Active » Closed (works as designed)
ahmadhalah’s picture

I have faced the same issue. I am surprised too that it isn't something that generates a warning, or at least info suggesting it be enabled on the Drupal status page. Also this issue didn't generate any errors in the Drupal log

I followed the same then its worked like charm

sudo a2enmod rewrite
sudo service apache2 restart

Thanks @desierto

cilefen’s picture

I don't think there is a simple and consistent way a CMS could detect that SELinux is denying write access. Access is simply denied.

slim ch’s picture

I had same issue on an image field with crop wiget and couldn't see the thumbnail also couldn't crop the image.
#5 resolved my issue.
thanks @desierto

naber’s picture

Had issue, solved when changed server from Apache + Nginx to just Apache in Openserver

sam452’s picture

So nginx is the cause?
Very interesting. So how to get around this?

webfab’s picture

Thanks @desierto and @ahmadhalah
#5 and #7 save my day.

nasseralikarimi’s picture

sudo a2enmod rewrite
sudo service apache2 restart

Working fine, Thanks @desierto and @ahmadhalah
There is no error and log to notice and debug.

Anonymous’s picture

thank you for all it's working

samar.alazzeh’s picture

#5 and #7 working fine with me.

manish34jain’s picture

#5 resolved my issue. Thanks

ajay gadhavana’s picture

@desierto #5 working for me. Thanks for saving my day

crutch’s picture

StatusFileSize
new69.83 KB

Experiencing this issue on windows dev machine using xampp, and LAMP environment on live server. mod_rewrite is on. Media Type is configured correctly. This happens whether mappings exist or not. I have to add the remote video (youtube or vimeo) and save. Delete the video, add the video again and then the thumbnail is generated.

The thumbnails then display for the media library.

Running cron, flushing cache, resaving the item results in no thumbnail.

References: https://www.drupal.org/project/drupal/issues/2629240#comment-14972304

canardesign’s picture

Hi ! same problem here, on Drupal 9.5.7
On production server as well as on Xampp, no images styles are being generated, for any style.
File system seems ok, other website on same Xampp generate style with no problem.
I know the problem comes from this website configuration or some module breaking the processing of image styles but how to debug this ?
I tried to dpm() in ImageStyleDownloadController::deliver and ImageStyle::createDerivative with no result.
Has anybody any idea on how to deal with this ?

cilefen’s picture

Yes. Use DDEV or Lando.

carp-enter’s picture

Thanks @desierto and @ahmadhalah
#5 and #7 save my day.
Ubuntu and Apache2

jaesperanza’s picture

In our experience, on Siteground's NGINX hosting, a common issue for Drupal 8/9. For one particular project we inherited, also on SG, we noticed the following is enabled and set to true in settings.php:

$config['image.settings']['suppress_itok_output'] = TRUE;
$config['image.settings']['allow_insecure_derivatives'] = TRUE;

Disabling both, seems to fix the issue.

scottholmes’s picture

Thanks for that headsup on mod rewrite. After spending hours chown, chgrp, and permissions this is what fixed it for me on Drupal 10.1.6

scottholmes’s picture

rmcf’s picture

Have the same problem on Drupal 10.1.6 at the shared web-hosting with Apache 2.4.58 and PHP 8.1.25. To make custom images styles working and thumbnails visible I have commented options in /public_html/sites/default/files/.htaccess and now it looks like this:

# Turn off all options we don't need.
# Options -Indexes -ExecCGI -Includes -MultiViews

I am not sure is that the safest solution but it works for me.

alfattal’s picture

After running the command $ sudo a2enmod rewrite, I started to get 403 forbidden error. What am I missing?!

ahmadhalah’s picture

@alfattal would you please share your virtual host configurations?

pearl.liang’s picture

I am using Drupal 10.3.1 on a shared Hostinger server. I had the same issue and the line below on settings.php solved it.

$config['image.settings']['allow_insecure_derivatives'] = TRUE;

travisc’s picture

If you add to a public server $config['image.settings']['allow_insecure_derivatives'] = TRUE; basically anyone can hit the backend and generate images, which could easily DDOS your server.