I have the following simple script to test the mkdir () function in PHP:
<?php $id = rand(); $targetPath = $_SERVER['DOCUMENT_ROOT'] . '/sample_folder/' . $id .'/'; mkdir(str_replace('//','/',$targetPath), 0755, true); ?>
Ideally, this will create a random folder each time the script is run in my web directory / sample_folder. Sample_folder has 755 permissions.
The problem I am facing is that I continue to work in PHP: mkdir () Permission denied issues. My sample_folder permissions are currently set to chmod 755.
EVERYTHING I have a reading state not from chmod to 777, so please do not suggest this.
For testing purposes, chmod 777 refers to the sample_folder directory, but again this creates security issues. Is there anything else that I am missing on how to make this work?
Note: my PHP users on the system are "apache";
I am using PHP 5.3. * and CentOS 5.5 on the dedicated Media Temple virtual server for reference. I also looked through almost every chmod question about SO and cannot find a solution that matches my problem (with the exception of 777 suggestions).
change
Running ls -la on my server returns:
drwxr-xr-x 2 ftphiddenname psacln 4096 Jan 26 11:24 sample_folder
final update
The answers received were very helpful. For anyone looking for additional information, I came across this knowledge base article and, as long as it is listed in Media Temple, I blieve the principles apply to any of the most similar configurations:
(dv): resolve Apache permission errors