<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() 也会对文件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                      <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>