title: PHP: way to get the true /tmp path?
body: <p>I'm moving my web app from CentOS 5 to CentOS 7, and new security features regarding the /tmp directory are breaking my code. I'm wondering how best to handle it.</p>
  
  <p>I have PHP code that creates a LaTeX file, then executes commands to turn that into a PDF, and then serves that to the user with appropriate headers. Here are some of the relevant lines of code as it stands now:</p>
  
  <pre><code>$fileroot = "/tmp/addr".getmypid();
  ob_start();
  /* echo all the LaTeX stuff */
  file_put_contents($fileroot.".tex",ob_get_contents());
  ob_end_clean();
  exec("cd /tmp;uplatex -interaction=batchmode --output-directory=/tmp $fileroot", $output, $return);
  </code></pre>
  
  <p>The settings in /usr/lib/systemd/system/php-fpm.service include <code>PrivateTmp=true</code>, which causes <code>/tmp</code> within PHP function calls to really be <code>/tmp/systemd-private-6898f2d665d64b998981bc479ddc2306-php-fpm.service-KU8XML/tmp</code>. Yikes! That's fine for security, but exec() uses the <code>/tmp</code> path literally, so it can't find the file that <code>file_put_contents()</code> just created. The PHP function <code>sys_get_temp_dir()</code> just returns <code>/tmp</code>, and I can't find any environment variables with that path in them. Is there a way to get that path programmatically? Or do I need to turn off PrivateTmp? Or is there a better way to do what I need to do? Yes, I could create my own special spot with wide-open permissions, but it seems like it should be cleaner to just use the normal temporary directory.</p>