1

Using PHP v5.6.40 under Ubuntu 18.04.04 (through php5.6 apache mod), this is the line of code:

file_put_contents('/tmp/deploy.hook.log', date('Y-m-d H:i:s') . ': ' . $data . "\n", FILE_APPEND);

It works in every other server / environment I have set but not here for some reason, no PHP errors or permission issues; the function also returns the number of bytes written even though the file remains empty.

Other interesting thing is that if I run the code using the php cli as www-data it works fine.

Any thoughts?

Emanuel
  • 43
  • 6
  • Apache version is 2.4.29 – Emanuel Mar 18 '20 at 17:07
  • Temporarily add `print_r($_FILES);` because I think you are probably making an upload form. Check the output. If it is empty, then I will help you with that. – Example person Mar 18 '20 at 17:10
  • @Chi.C.J.RajeevaLochana $_FILES is an empty array, no upload is being made here. – Emanuel Mar 18 '20 at 17:14
  • Does the server have space? Maybe `tmp` is being empty immediately after – user3783243 Mar 18 '20 at 17:16
  • 1
    Some systems fake `/tmp` in order to isolate processes from each other. If you're using Apache on CentOS this is likely the case. You'll probably find your actual tmp folder like `/tmp/systemd-private-1234reallylongidhere` from outside of Apache. – Sammitch Mar 18 '20 at 17:18
  • @user3783243 interesting thing I just found, switching to another directory worked, even though /tmp has plenty of space AND by default the permissions are 777 – Emanuel Mar 18 '20 at 17:20
  • @Emanuel, saying ***no PHP errors or permission issues***, don't say that before you really know the problem. It could be a ownership permission problem. – Example person Mar 18 '20 at 17:27

1 Answers1

2

It seems the comment made by Sammitch was correct, my true /tmp dir is something like /tmp/systemd-private-{some-hash}

Emanuel
  • 43
  • 6
  • I would suggest not using `/tmp` for files that you need to access outside of the context of the process that's creating them. You may see others recommending to disable the "Private Tmp" setting, but that would be a big security no-no in my book. – Sammitch Mar 18 '20 at 17:29
  • Thanks for the suggestion, this is just a test server without access outisde our local network that's why the path was /tmp – Emanuel Mar 18 '20 at 17:32
  • Docs: https://www.freedesktop.org/software/systemd/man/systemd.exec.html#PrivateTmp= – Sammitch Mar 18 '20 at 17:32
  • 1
    Tests and PoCs become production deployments with shocking frequency. ;) – Sammitch Mar 18 '20 at 17:33