开发者

Apache Folder Permissions

开发者 https://www.devze.com 2023-01-16 08:11 出处:网络
When I create a directory with PHP\'s mkdir(), the folders\' owner is \'apache\'. When I create a directory over FTP, the owner is \'ftpadmin\'.

When I create a directory with PHP's mkdir(), the folders' owner is 'apache'. When I create a directory over FTP, the owner is 'ftpadmin'.

For some strange reason, with PHP's rename() function I can't move any files into a directory owned by 'apache'. I've chmod() both the file and the directory to 777 and 0777, but 'apache' refuses to move any files into directories it created. I can have 'apache' move files into an 'ftpadmin' directory. I've tried chmod() and mkdir() with 777, 0777, 755, 0755, 1777, 01777 and more.

The directories need to be dynamically generated by my client, and files need to be moved in and out.

The server is a dedicated-virtual se开发者_JS百科rver that I have can ssh into and have admin rights to.


Perhapse safe-mode features? http://www.php.net/manual/en/features.safe-mode.functions.php

rename() Checks whether the files or directories being operated upon have the same UID (owner) as the script that is being executed. Checks whether the directory in which the script is operating has the same UID (owner) as the script that is being executed.

If safe mode is on, turn it of, and solve the functionality it provides at a proper level. If this isn't the problem, showing the actual error php undoubtedly emits could help us a lot.


PHP is running as user Apache. Your FTP account is running as user 'fpadmin'. This is why the owners are different. Have you tried chown() php function (http://php.net/manual/en/function.chown.php)? This will change the owner of a file/directory.

Cheers


Ugh, my first down vote. That stings.. That was a stupid answer though..

Alright, so I'm trying to understand your question/replicate your error. Here's what I've tried and here are my results. Hopefully it will at least be of some use to you.

I have the following directory structure:

/var/www/public_html/test (chmod = 777 via SSH, owned by 'ftpuser')
/var/www/public_html/test/index.php (chmod = 777 via SSH, owned by 'ftpuser')
/var/www/public_html/test/ftp_owned.file (chmod = 644 (default), owned by 'ftpuser')

Then in the index.php file I have the following code:

mkdir("./downvoted");
chmod("./downvoted", 0777);
$h = fopen("./i_am_so.sad", "x+");
fwrite($h, "attempting to redeem myself");
fclose($h);
rename("./i_am_so.sad", "./downvoted/i_am_so.sad");
rename("./ftp_owned.file", "./downvoted/ftp_owned.file");

Resulting in a new directory structure:

/var/www/public_html/test (chmod = 777 via SSH, owned by 'ftpuser')
/var/www/public_html/test/index.php (chmod = 777 via SSH, owned by 'ftpuser')
/var/www/public_html/test/downvoted (chmod = 0777 via PHP, owned by 'apache')
/var/www/public_html/test/downvoted/i_am_so.sad (permissions = 644 (default), owned by 'apache')
/var/www/public_html/test/downvoted/ftp_owned.file (permissions = 644 (default), owned by 'ftpuser')

Still sad as I wasn't able to reproduce the error nor redeem myself. Hopefully you can either post the error you are receiving (permission denied?) or point out how my experiment differs from your application.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号