<legend id='unmdZ'><style id='unmdZ'><dir id='unmdZ'><q id='unmdZ'></q></dir></style></legend>
  • <tfoot id='unmdZ'></tfoot>
    • <bdo id='unmdZ'></bdo><ul id='unmdZ'></ul>

      <small id='unmdZ'></small><noframes id='unmdZ'>

      <i id='unmdZ'><tr id='unmdZ'><dt id='unmdZ'><q id='unmdZ'><span id='unmdZ'><b id='unmdZ'><form id='unmdZ'><ins id='unmdZ'></ins><ul id='unmdZ'></ul><sub id='unmdZ'></sub></form><legend id='unmdZ'></legend><bdo id='unmdZ'><pre id='unmdZ'><center id='unmdZ'></center></pre></bdo></b><th id='unmdZ'></th></span></q></dt></tr></i><div id='unmdZ'><tfoot id='unmdZ'></tfoot><dl id='unmdZ'><fieldset id='unmdZ'></fieldset></dl></div>

        即使具有完全打开的权限,PHP fopen() 也会对文件失败

        PHP fopen() fails on files even with wide-open permissions(即使具有完全打开的权限,PHP fopen() 也会对文件失败)
      1. <tfoot id='Uq2Z5'></tfoot>

            <bdo id='Uq2Z5'></bdo><ul id='Uq2Z5'></ul>
              <tbody id='Uq2Z5'></tbody>

                  <i id='Uq2Z5'><tr id='Uq2Z5'><dt id='Uq2Z5'><q id='Uq2Z5'><span id='Uq2Z5'><b id='Uq2Z5'><form id='Uq2Z5'><ins id='Uq2Z5'></ins><ul id='Uq2Z5'></ul><sub id='Uq2Z5'></sub></form><legend id='Uq2Z5'></legend><bdo id='Uq2Z5'><pre id='Uq2Z5'><center id='Uq2Z5'></center></pre></bdo></b><th id='Uq2Z5'></th></span></q></dt></tr></i><div id='Uq2Z5'><tfoot id='Uq2Z5'></tfoot><dl id='Uq2Z5'><fieldset id='Uq2Z5'></fieldset></dl></div>
                  <legend id='Uq2Z5'><style id='Uq2Z5'><dir id='Uq2Z5'><q id='Uq2Z5'></q></dir></style></legend>
                • <small id='Uq2Z5'></small><noframes id='Uq2Z5'>

                • 本文介绍了即使具有完全打开的权限,PHP fopen() 也会对文件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在将我的 LAMP 从我的 Windows Server 迁移到运行 Debian 6 的 VPS.大多数一切正常,但是,其中一个 PHP 脚本未能写入其配置的日志文件.我不知道为什么,所以我写了一个新的、简单的、人为的 PHP 脚本来测试这个问题.

                  I'm currently migrating my LAMP from my Windows Server to a VPS running Debian 6. Most everything is working, however, one of the PHP scripts was failing to write to its configured log file. I could not determine why, so I wrote a new, simple, contrived PHP script to test the problem.

                  <?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.
                  • 目录和文件都归www-data:www-data所有.
                  • 该文件是使用 touch 创建的.
                    • While I would never do it normally, to help diagnose, I set /var/log/apache2/writetest/writetest.log to chmod 777.
                    • Both the directory and the file are owned by www-data:www-data.
                    • The file was created with touch.
                    • 我运行 strace 来验证哪个进程正在执行打开:

                      I ran strace to verify which process was performing the 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-data 下运行的 apache2 子进程之一.如您所见,我还在脚本中包含了 echo exec('whoami'); ,以确认脚本正在由 www-data 运行.

                      I checked and pid 21931 was indeed one of the apache2 child processes running under www-data. As you can see, I also included echo exec('whoami'); in the script which confirmed the script was being run by www-data.

                      其他注意事项:

                      • PHP 未在安全模式下运行
                      • PHP open_basedir 未设置
                      • 版本信息:Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze3 with Suhosin-Patch mod_ssl/2.2.16 OpenSSL/0.9.8o
                      • uname -a: 2.6.32-238.19.1.el5.028stab092.2 #1 SMP Thu Jul 21 19:23:22 MSD 2011 x86_64 GNU/Linux
                      • 这是在 OpenVZ 下运行的 VPS 上
                      • ls -l (file): -rwxrwxrwx 1 www-data www-data 0 Sep 8 18:13 writetest.log
                      • ls -l(目录):drwxr-xr-x 2 www-data www-data 4096 Sep 8 18:13 writetest
                      • Apache2的父进程运行在root下,子进程运行在www-data
                      • selinux 未安装(感谢 Fabio 提醒我提及这一点)
                      • 我已经多次重启 apache 并重启服务器
                      • PHP is not running in safe mode
                      • PHP open_basedir is not set
                      • Version info: Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze3 with Suhosin-Patch mod_ssl/2.2.16 OpenSSL/0.9.8o
                      • uname -a: 2.6.32-238.19.1.el5.028stab092.2 #1 SMP Thu Jul 21 19:23:22 MSD 2011 x86_64 GNU/Linux
                      • This is on a VPS running under OpenVZ
                      • ls -l (file): -rwxrwxrwx 1 www-data www-data 0 Sep 8 18:13 writetest.log
                      • ls -l (directory): drwxr-xr-x 2 www-data www-data 4096 Sep 8 18:13 writetest
                      • Apache2's parent process runs under root, and the child processes under www-data
                      • selinux is not installed (thanks to Fabio for reminding me to mention this)
                      • I have restarted apache many times and rebooted the server as well

                      推荐答案

                      请记住,为了访问文件,所有父目录必须可以被 www-data 读取.您的 strace 输出似乎表明即使 accessing /var/log/apache2/writetest 也失败了.确保 www-data 对以下目录具有权限:

                      Remember that in order to reach a file, ALL parent directories must be readable by www-data. You strace output seems to indicate that even accessing /var/log/apache2/writetest is failing. Make sure that www-data has permissions on the following directories:

                      • /(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-)

                      这篇关于即使具有完全打开的权限,PHP fopen() 也会对文件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                      本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Appending GET parameters to URL from lt;formgt; action(将 GET 参数附加到来自 lt;formgt; 的 URL行动)
                  Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
                  PHP - get certain word from string(PHP - 从字符串中获取某个单词)
                  How to debug a get request in php using curl(如何使用 curl 在 php 中调试 get 请求)
                  get a # from a url in php(从 php 中的 url 获取 #)
                  PHP - include() file not working when variables are put in url?(PHP - 将变量放入 url 时,include() 文件不起作用?)

                      <bdo id='9UeI4'></bdo><ul id='9UeI4'></ul>

                        1. <legend id='9UeI4'><style id='9UeI4'><dir id='9UeI4'><q id='9UeI4'></q></dir></style></legend>

                          <small id='9UeI4'></small><noframes id='9UeI4'>

                          <tfoot id='9UeI4'></tfoot>

                              <tbody id='9UeI4'></tbody>
                            <i id='9UeI4'><tr id='9UeI4'><dt id='9UeI4'><q id='9UeI4'><span id='9UeI4'><b id='9UeI4'><form id='9UeI4'><ins id='9UeI4'></ins><ul id='9UeI4'></ul><sub id='9UeI4'></sub></form><legend id='9UeI4'></legend><bdo id='9UeI4'><pre id='9UeI4'><center id='9UeI4'></center></pre></bdo></b><th id='9UeI4'></th></span></q></dt></tr></i><div id='9UeI4'><tfoot id='9UeI4'></tfoot><dl id='9UeI4'><fieldset id='9UeI4'></fieldset></dl></div>