11

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!

2

5 Answers 5

10

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);
2
  • I did, it does not help unfortunately. this lead me to believe, there is some other file that need to be edited?
    – Skypiboy
    Commented Jan 28, 2016 at 12:59
  • Downvoted, the permissions should be rectified on the server, not by modifying core files in the system.
    – zigojacko
    Commented Aug 12, 2016 at 10:59
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
2
  • This is certainly the more correct way of doing things. Unfortunately the answer does not apply for all. Commented Aug 9, 2016 at 23:26
  • 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.
    – zigojacko
    Commented Aug 12, 2016 at 11:00
2

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.

0
1
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))) {
1
  • Downvoted, the permissions should be rectified on the server, not by modifying core files in the system.
    – zigojacko
    Commented Aug 12, 2016 at 11:00
0

This solution worked for us for the same issue. Spent roughly 10 hours looking for a solution glad we found it.

Please see solution and referenced link.

Click Here to see solution link

Solution: Magento Community Edition 1.9.2.3 and the Security Patch SUPEE-7405 introduced a new bug with image uploading which resulted in incorrect file permissions for newly uploaded images.

If you have uploaded any images which are not showing up, the first thing to do is to set the correct file permissions for your files and databases.

To permanently resolve the problem, you will need to modify a file within Magento.

Important Note: This is a manual hack which will be overwritten during a Magento upgrade.

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);

Save the file and the next image uploaded should load properly.

4
  • 1
    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. Commented Jan 28, 2016 at 20:38
  • 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. Commented Jan 29, 2016 at 21:32
  • 2
    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/… Commented Jan 29, 2016 at 21:40
  • This is not a solution as per @mtinsley comments above hence my downvote.
    – zigojacko
    Commented Aug 12, 2016 at 10:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.