Can't write to /tmp with php, despite 777 permissions and no open_basedir value

前端 未结 4 1853
花落未央
花落未央 2020-12-29 02:16

I\'m trying to write a file to my /tmp directory (on an apache server) with the php fopen function, but it fails:

<         


        
相关标签:
4条回答
  • 2020-12-29 02:50

    Your problem is likely caused by the combination of systemd and apache. It's a security feature called PrivateTmp, and obviously it's an opt out.

    If you don't want it, you can disable it like this:

    1. Outcomment the respective switch in /etc/systemd/system/multi-user.target.wants/apache2.service: #PrivateTmp=true
    2. Restart systemd: sudo systemctl daemon-reload
    3. Restart apache: sudo systemctl restart apache2
    0 讨论(0)
  • 2020-12-29 02:50

    According to the error message displayed, there is no folder /tmp/. Perhaps the tmp folder is somewhere else than the root?

    This error will not show if the file actually doesn't exist, as it will attempt to create it.

    Method x also returns a warning if the file already exists. (doc: http://www.php.net/manual/en/function.fopen.php)

    I think this also goes for another reason this could go wrong, is the user which executes PHP doesn't have rights to write in the /tmp/ folder.

    0 讨论(0)
  • 2020-12-29 03:05

    I had exactly the same problem. PHP reported no problem with opening file in /tmp/myoutputfile, but no file was in that path. Then I did

    find / -name "myoutputfile"
    

    and found it in /tmp/systemd-…/myoutputfile. I've found this article on Google.
    So, in my case, it was a Systemd and Apache Httpd combination. I hope this will help to someone.

    0 讨论(0)
  • 2020-12-29 03:05

    Try to add /tmp to open_basedir. For example:

        php_admin_value open_basedir /some/path:/another/path:/tmp
    

    I'm not sure this is the problem you actually faced, but I found your question while looking for this solution so I guess that might help someone else.

    0 讨论(0)
提交回复
热议问题