7

I'm moving a website in a production server and it appears that the image thumbnails aren't created from an Image Field in a content.

The images are uploaded correctly but no files are created in styles folder. I've already set to 0777 each folder in case of a permission problem, but it's not that.

The big problem is that I can't remove the images, probably because it raises a forbidden file as it doesn't exist. The only error log I can find is an access denied but nothing else.

Does anybody has the same problem ?

It works okay on local... maybe an Apache issue to look at ?

enter image description here

3
  • 1
    maybe because you have the wrong user as the folder owner. If you're using ubuntu, inside your Drupal folder try sudo chown www-data -R sites
    – No Sssweat
    Jun 13, 2016 at 23:20
  • yes it appears that there was a permission folder problem. I couldn't use sudo as it is on a hosted server but by reinstalling totally drupal it looks okay Jun 14, 2016 at 8:06
  • I managed to solve it using this: drupal.stackexchange.com/a/230392/73476
    – Nick G
    Mar 5, 2017 at 12:30

7 Answers 7

11

Solution for Drupal 8 that worked for me:

  • create sites/default/files/styles folder manually
  • set its permissions to 775
  • create .htaccess file in this folder with following content:
<Files *>
  SetHandler none
</Files>
3
  • i added files folder and every folder inside it 775 permission and now works(didn't had to modify .htaccess). Thank you!
    – David
    May 26, 2017 at 8:46
  • 1
    Simply adding .htaccess worked for me. The bigger question is, why is this necessary? sites/default/styles already existed with 775 perms, and Drupal had already been creating files on the server right and left.
    – kentr
    Nov 29, 2019 at 4:19
  • drupal.stackexchange.com/a/289378/6884 answered it
    – izus
    Apr 30, 2021 at 13:49
4

Having the same problem with a brand new Ubuntu 19.10 installation on development laptop.

As suggested in https://drupal.stackexchange.com/a/224999/97472, adding

<Files *>
  SetHandler none
</Files>

is fixing a problem, image style generation works fine. However, this is not an optimal solution. Finally, figured out that i forgot to add apache mod-rewrite module. Executing next lines in console fixed the problem fully, no need for .htaccess manual fix:

sudo a2enmod rewrite
systemctl restart apache2
2

Sometimes this is related to an odd space in one of your module or PHP files before the opening PHP tag... for example:

_
<?php

/**
 * Stuff here.
 */

That little line where the underscore is present can cause thumbnails to break on first render. See: Image styles not generated on first page load until page refreshed on Drupal.org.

To see if this might be your issue, grep your entire codebase for any files that have a newline, then a <?php tag. In my case, I found that the contrib Block Styles module had a submodule with a newline before the opening tag, and that caused a fair amount of grief!

1

From settings.php Drupal 8, please try add following:

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

suppress_itok_output = True for remove itok token from image.

4
  • 1
    This works but opens up the site for possible DDoS attacks.
    – Benedikt
    Oct 27, 2018 at 8:36
  • drupal.org/forum/newsletters/…
    – Benedikt
    Oct 27, 2018 at 8:38
  • This is security vulnerability? Oct 28, 2018 at 19:23
  • "Posted by Drupal Security Team on 20 Feb 2013 at 20:50 UTC Advisory ID: DRUPAL-SA-CORE-2013-002 Project: Drupal core Version: 7.x Date: 2013-February-20 Security risk: Critical Exploitable from: Remote Vulnerability: Denial of service Description Drupal core's Image module allows for the on-demand generation of image derivatives. This capability can be abused by requesting a large number of new derivatives which can fill up the server disk space, and which can cause a very high CPU load. Either of these effects may lead to the site becoming unavailable or unresponsive."
    – Benedikt
    Nov 5, 2018 at 8:11
1

I used this snippet code which forces drupal to create image style for an image :

$styles = ImageStyle::loadMultiple();
$image_uri = $entity->getFileUri();
/** @var \Drupal\image\Entity\ImageStyle $style */
foreach ($styles as $style) {
  $destination = $style->buildUri($image_uri);
  $style->createDerivative($image_uri, $destination);
}

this code can be used in a function iterating on a group of nodes, select their image and create styles for them or could be used as file upload hook so any time an image is uploaded the styles would be created manually.

0

Drupal 8 solution for drupal image styles not generating:

set the permissions to 775 to sites/default/files/ folder. command [ $ sudo chmod 775 /var/www/html/drupal-8.7.6/sites/default/files/]

Comment the "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003" line in files folder .htaccess file.

Add the following lines in .htaccess file.

# Override the handler again if we're run later in the evaluation list. #SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003 SetHandler none

0

Having tried multiple owner change commands and permissions did not work. The solution was simply :

sudo a2enmod rewrite

systemctl restart apache2

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.