Magento 1.9.2.3, after uploading images from backend, permission is set to 640 instead 644

11,513

Solution 1

Open up the following file:

lib/Varien/File/Uploader.php

Look for this line:

chmod($destinationFile, 0640);

Replace it with this line:

chmod($destinationFile, 0644);

Look for this line:

chmod($destinationFile, 0750);

Replace it with this line:

chmod($destinationFile, 0755);

Solution 2

Magento 1.9.2.3 or SUPEE-7405 include some changes to file permissions. Files uploaded via the Magento admin panel (i.e. product image uploads) are no longer world readable by default (before: 644 / after: 640). Directories are also not world executable (before: 755 / after: 750). This results in the web service being unable to read newly created files from Magento.

Solution is not changing the core files to change the file permissions but add the user that runs the web service to the group of the PHP configured user. For example i'm running nginx on my server so this is what I had to do to resolve the issue:

  • usermod -a -G groupname username usermod -a -G
  • php-fpm-configured-groupname nginx

Solution 3

Upgrade to Magento 1.9.2.4 which addresses the issues caused by patch SUPEE-7405, or Magento 1.9.2.3. If for some reason you can't upgrade then you should install SUPEE-7405 v 1.1 which will rectify the permissions issue. This patch in Magento's own words restores less restrictive file permissions (0666 for files and 0777 for directories) which will enable you to view images etc as normal.

Solution 4

file:- lib/Varien/File/Uploader.php


line 219:

chmod($destinationFile, 0640);
chmod($destinationFile, 0644);



line 541:

if (!(@is_dir($destinationFolder) || @mkdir($destinationFolder, 0750, true))) {

to:

if (!(@is_dir($destinationFolder) || @mkdir($destinationFolder, 0755, true))) {
Share:
11,513

Related videos on Youtube

Skypiboy
Author by

Skypiboy

Updated on August 22, 2022

Comments

  • Skypiboy
    Skypiboy over 1 year

    After doing a fresh install of magento 1.9.2.3 I realized that there is a problem when I upload images from the backend. the files get the permission 640 instead 644. How can I adjust this so that when magento uploads an image to the server, it gets 644 ?

    At the moment I have to use SSH or acp to manually set the permissions right.

    thanks allot!

  • Mathew Tinsley
    Mathew Tinsley about 8 years
    This solution reintroduces the problem that the patch fixed. You don't need to make any modifications to core files to fix the problem, you just need to configure your permissions so the webserver is either the owner of the files or in the files' group.
  • Daniel Macadar
    Daniel Macadar about 8 years
    mtinsley, This issue was actually presented after the latest patch was installed. Even if the permissions on the webserver are correct, newly uploaded files will still upload with wrong permissions. The latest patch applied in this case was 7405 which was release January 20, 2016. The solution above worked for us in 2 sites.
  • Mathew Tinsley
    Mathew Tinsley about 8 years
    With the patch, Magento sets permissions in a way that is consistent with Magento's recommended file permissions. Making a core modification to Magento in order to grant more privileges than what is necessary fixes the problem, but that doesn't make it correct. You can also resolve this issue, without touching Magento, by adding the webserver to the file's group. devdocs.magento.com/guides/m1x/install/…
  • Chris Sobolewski
    Chris Sobolewski over 7 years
    This is certainly the more correct way of doing things. Unfortunately the answer does not apply for all.
  • zigojacko
    zigojacko over 7 years
    This is not a solution as per @mtinsley comments above hence my downvote.
  • zigojacko
    zigojacko over 7 years
    Downvoted, the permissions should be rectified on the server, not by modifying core files in the system.
  • zigojacko
    zigojacko over 7 years
    This is the correct answer. The default system user needs read/write access in the same group as the one that owns the files/folders. Set this correctly and the problem will be resolved.