dir permission problem when creating new dirs

Hi All,

I am having the problem with new created dir from the php code. The problem is caused by the owner settings when creating new dirs. What happens here is as follows:

1) it creates a new dir with owner apache and cmod 666

2) next, when I try to upload images to the created, nothing is uploaded

3) if I change the owner of new directories to my ftp owner (let's say "cinema" as all the directories in the root), everything works fine

My php settings in the conf file: Safe mode Off, RegGlobals Off.

chmod 666 should allow accessing the dir by anyone, but it does not happen

What is wrong here? How can I fix this?

Thanks
andy7789Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
6 => Read and Write. You need to be able to execute the script:
777
0
andy7789Author Commented:
Why? there are no executables here. this is just a dir for image iploading
0
Steve BinkCommented:
The execute permission is necessary to be able to traverse the directory.

http://www.zzee.com/solutions/linux-permissions.shtml#zzee_link_9_1077830297
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

hieloCommented:
>>Why? there are no executables here
Basically the web server need to be able to "read/access" the directory. For that you need execute permissions.
If you were to set up an html file  with 744 permisssions, it would not be viewable by the public because you do not have execute permission for the "Other" group. You would need at least a 5 =>(755).
0
andy7789Author Commented:
thank you. Is there any way to set the default cmod for new dirs in .htaccess (to override any other settings)?
0
hieloCommented:
Now that you know it works with 777 you know your script is OK. So, try 766 instead of 777.


>> Is there any way to set the default cmod for new dirs in .htaccess (to override any other settings)?
# ensure CHMOD settings for specified file types
# remember to never set CHMOD 777 unless you know what you are doing
# files requiring write access should use CHMOD 766 rather than 777
# keep specific file types private by setting their CHMOD to 400
chmod .htpasswd files 640
chmod .htaccess files 644
chmod php files 600
0
Steve BinkCommented:
>>> Is there any way to set the default cmod for new dirs in .htaccess

None that I am aware of.  You could write a call to umask() into the script, and any files created under that script session should use it.  Otherwise, Apache inherits the umask setting from the user that started the server.  Both options affect all directories.

Why not just set the permissions on the file after it is created?
0
andy7789Author Commented:
i do not know why, but I could never managed to make it like

mkdir('dir', 0777)

Usually, i used exec("chmod..."), which does not run on all servers.

Any ideas as why the direct execution of mkdir with chmod param does not work?

0
Steve BinkCommented:
What permissions did it receive after you created the directory?  Remember that you have to account for PHP's umask when assigning the permissions.  The actual permissions assigned are (supplied - umask).
0
andy7789Author Commented:
i am getting 666, even though it should be 777 as specified in mkdir
0
Steve BinkCommented:
What does PHP's umask() return?
0
jmlonCommented:
I suggest you try instead setting the permissions of the directory with the chmod command from within the script.
The PHP's chmod man page includes several examples of how to do this:
http://www.php.net/chmod
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve BinkCommented:
That was my suggestion, too.  :)  It does seem to be easier, but there is a point in the user comments about a vulnerability inherent in that strategy.
0
andy7789Author Commented:
yes, adding chmod() after each mkdir() works fine. I still do not understand, why mkdir dies not set it directly.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.