简体   繁体   English

Apache文件夹权限

[英]Apache Folder Permissions

When I create a directory with PHP's mkdir() , the folders' owner is 'apache'. 当我使用PHP的mkdir()创建目录时,文件夹的所有者为'apache'。 When I create a directory over FTP, the owner is 'ftpadmin'. 通过FTP创建目录时,所有者为“ ftpadmin”。

For some strange reason, with PHP's rename() function I can't move any files into a directory owned by 'apache'. 由于某些奇怪的原因,使用PHP的rename()函数,我无法将任何文件移动到“ 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. 我已经将文件和目录chmod()都设置为777和0777,但是'apache'拒绝将任何文件移动到它创建的目录中。 I can have 'apache' move files into an 'ftpadmin' directory. 我可以让“ apache”将文件移动到“ ftpadmin”目录中。 I've tried chmod() and mkdir() with 777, 0777, 755, 0755, 1777, 01777 and more. 我已经尝试将chmod()mkdir()与777、0777、755、0755、1777、01777等一起使用。

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 server 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 http://www.php.net/manual/zh/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. named()检查正在操作的文件或目录是否与正在执行的脚本具有相同的UID(所有者)。 Checks whether the directory in which the script is operating has the same UID (owner) as the script that is being executed. 检查脚本所在的目录是否与正在执行的脚本具有相同的UID(所有者)。

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发出的实际错误可能对我们有很大帮助。

PHP is running as user Apache. PHP以用户Apache的身份运行。 Your FTP account is running as user 'fpadmin'. 您的FTP帐户以“ fpadmin”用户身份运行。 This is why the owners are different. 这就是所有者不同的原因。 Have you tried chown() php function ( http://php.net/manual/en/function.chown.php )? 您是否尝试过chown()php函数( http://php.net/manual/en/function.chown.php )? This will change the owner of a file/directory. 这将更改文件/目录的所有者。

Cheers 干杯


Ugh, my first down vote. gh,我的第一票。 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: 然后在index.php文件中,我有以下代码:

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. 希望您可以发布您收到的错误(权限被拒绝?),或指出我的实验与您的应用程序有何不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM