PHP fopen()即使具有广泛的开放权限也会失败
我正在将我的LAMP从我的 Windows Server迁移到运行Debian 6的VPS.但是,大多数工作都是正常的,但是其中一个 PHP脚本无法写入其配置的日志文件.我无法确定为什么,所以我写了一个新的,简单的,有创意的PHP脚本来测试这个问题. <?php ini_set('display_errors',1); error_reporting(E_ALL); echo exec('whoami'); $log = fopen('/var/log/apache2/writetest/writetest.log','a'); if ($log != NULL) { fflush($log); fclose($log); $log = NULL; } ?> 但是,它失败了结果: www-data Warning: fopen(/var/log/apache2/writetest/writetest.log): failed to open stream: Permission denied in /var/www/_admin/phpwritetest.php on line 5 >虽然我永远不会正常进行,为了帮助诊断,我将/var/log/apache2/writetest/writetest.log设置为chmod 777. 我运行strace来验证哪个进程正在执行open: [pid 21931] lstat("/var/log/apache2/writetest/writetest.log",0x7fff81677d30) = -1 EACCES (Permission denied) [pid 21931] lstat("/var/log/apache2/writetest",0x7fff81677b90) = -1 EACCES (Permission denied) [pid 21931] open("/var/log/apache2/writetest/writetest.log",O_RDWR|O_CREAT|O_TRUNC,0666) = -1 EACCES (Permission denied) 我检查并且pid 21931确实是在www数据下运行的apache2子进程之一.正如你所看到的,我还包括echo exec(‘whoami’);在脚本中确认该脚本由www-data运行. 其他说明: > PHP没有以安全模式运行 > /(r-x)> / var(r-x)> / var / log(r-x)> / var / log / apache2(r-x)> / var / log / apache2 / writetest(rwx)> /var/log/apache2/writetest/writetest.log(rw-) (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |