Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a php files, name image_creat.php

$res = mysql_query("select * from images where key!='en' Order By id DESC LIMIT 0,10");
while ($rows = mysql_fetch_array($result)) 
$imageurl =  dirname(__FILE__) . '/../images/';
$width = $row['width'];
$height = $row['height'];
$source_image = @imagecreatefromjpeg($row['image']);
$desired_width = '800';
$desired_height = floor($height*($desired_width/$width));
$virtual_image = @imagecreatetruecolor($desired_width,$desired_height);

I use SSH to setting the permission for it:

chmod 0755 /var/www/html/php/image_creat.php
chown root:root /var/www/html/php/image_creat.php

Then also setting permission for the images folder:

chmod 0755 /var/www/html/php/images/

But after the php script create jpeg files, I find all the files with permission of 644, so that my browser refused to visit it. where is the problem? Thanks.

share|improve this question
Can you post the output of ls -l for both the images folder and some of its contents? We need to know the owner user and group. – Khaled Jan 23 '12 at 15:45
644 should be readable as well... – jjmontes Jan 23 '12 at 16:02
You might be able to use chmod directly in your script chmod("path/to/image.jpeg", 0755); As for the why - the user your php scripts run as is determined by the web server (e.g apache with mod_php will usually be apache or www-data; php-fpm will be based on the pool, etc) - this determines the owner, and the umask of that user determined the permissions of newly created files. That said, 644 should be readable (although, some setups do require execute permissions on php files, they shouldn't be needed on images). – cyberx86 Jan 23 '12 at 17:01
up vote 0 down vote accepted

I find all the files with permission of 644, so that my browser refused to visit it

Then either you're not telling us the whole story or your facts are mis-reported.

644 means -rw-r--r-- and since the creating script is only executable for root, the output ile will be owned by root. The file is readable by all users (including the webserver uid).

I suggest you go read up on Unix file permissions.

There might be lots of reasons why the file is not readable by the webserver uid - top of the list would be directory permissions (but if all the dirs above are 0755 - drwxr-xr-x - then that's not the cause) and ACLs.

BTW using the root account for routine data maintenance is a very bad idea.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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