Php has its own /tmp in /tmp/systemd-private-nABCDE/tmp when accessed through nginx

前端 未结 3 1180
無奈伤痛
無奈伤痛 2021-02-05 05:25

I found strange behaviour concerning php and /tmp folder. Php uses another folder when it works with /tmp. Php 5.6.7, nginx, php-fpm.

相关标签:
3条回答
  • 2021-02-05 05:37

    If you are running multiple sites on the server then I think you'll want to leave PrivateTmp=yes so that each site remains segregated even in it's use of temp files. Could be a security issue otherwise, I'd imagine.

    0 讨论(0)
  • 2021-02-05 05:41

    Ignacio Vazquez-Abrams have the correct answer, but let me add my functional solution.

    I've try "multi-user.target.wants" solution, it have worked but after restart, but at some point, PrivateTmp go back to true. Like my principal use of Apache2 is PHP, I finally edited php.ini and I've uncomment line sys_temp_dir.

    By default system use temp dir assigned by function sys_get_temp_dir. Function sys_get_temp_dir will return "/tmp" but the truth is that your tmp files are storing at some path like /tmp/systemd-private-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-apache2.service-YYYYYY//tmp/*. So, what work for me was:

    Edit php.ini (path can change between PHP versions)

    sudo nano /etc/php/7.2/cli/php.ini
    

    Then uncomment sys_temp_dir line

    ; Directory where the temporary files should be placed.
    ; Defaults to the system default (see sys_get_temp_dir)
    sys_temp_dir = "/tmp"
    
    0 讨论(0)
  • 2021-02-05 05:42

    Because systemd is configured to give nginx a private /tmp. If you must use the system /tmp instead for some reason then you will need to modify the .service file to read "PrivateTmp=no".

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