title: Got error 'PHP message: PHP Notice: Unknown: file created in the system's temporary directory in Unknown on line 0\nPHP message: PHP Warning:
body: <p>PHP Warning: File upload error - unable to create a temporary file in Unknown</p>
  
  <p>This is a problem that keeps recurring.</p>
  
  <p>We have servers with PHP FPM and for some strange reason this problem keep happening:</p>
  
  <pre><code>Got error 'PHP message: PHP Notice: Unknown: file created in the system's temporary directory in Unknown on line 0\nPHP message: PHP Warning: File upload error - unable
      to create a temporary file in Unknown on line 0\n'.
  </code></pre>
  
  <p>Our user php conf looks like the following when it first happened:</p>
  
  <pre><code>[USER]
  user = $pool
  group = $pool
  listen = /usr/local/php72/sockets/$pool.sock
  listen.owner = $pool
  listen.group = apache
  listen.mode = 660
  pm = ondemand
  pm.max_children = 100
  pm.process_idle_timeout = 20
  php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f USER@domain.tld
  php_admin_value[session.save_path] = /home/USER/tmp
  php_admin_value[open_basedir] = /home/USER/:/tmp/:/var/tmp/:/usr/local/php72/lib/:/usr/local/php54/lib/:/usr/local/php55/lib/:/usr/local/php56/lib/:/usr/local/php70/lib/:/usr/local/php71/lib/:/usr/local/php72/lib/:/usr/local/lib/php/
  php_admin_value[mail.log] = /home/USER/.php/php-mail.log
  security.limit_extensions = .php .php52 .php53 .php54 .php55 .php56 .php60 .php70 .php71 .inc .php72
  </code></pre>
  
  <p>It was thought that the actual fix was, by adding the tmp variables in the user php fpm conf:</p>
  
  <pre><code>env[TMP] = /tmp
  env[TMPDIR] = /tmp
  env[TEMP] = /tmp
  </code></pre>
  
  <p>Restart php-fpm, the problem seemed fix at first. But, our websites still cannot upload files.</p>
  
  <p>The temporary fix seems to restart php fpm. But, after a while the problem happens again.
  And the conf still has the /tmp variables.</p>
  
  <p>We added, in all the php.ini we could find, the <code>upload_tmp_dir = /tmp</code>, and that also was a temporary fix.</p>
  
  <hr>
  
  <p>This has happened on multiple shared and dedicated servers, with multiple websites.</p>
  
  <p>I did a test on our test server:
  <code>sys_get_temp_dir()</code>: gives the </p>
  
  <p><code>/tmp</code></p>
  
  <p><code>ini_get('upload_tmp_dir')</code>: gives no value:</p>
  
  <p><code>string(0) ""</code></p>
  
  <p>But my test files uploaded fine</p>
  
  <p>Test code used from:<a href="https://www.w3schools.com/php/php_file_upload.asp" rel="nofollow noreferrer">https://www.w3schools.com/php/php_file_upload.asp</a></p>
  
  <p><code>PrivateTmp=true</code> is set to true on the PHP FPM instance. This should not have any effect, because we are giving /tmp as the specified dir...?</p>
  
  <p>Is there any way how to permanently fix this issue?</p>
  
  <ul>
  <li>CentOS Linux release 7.5.1804 (C</li>
  <li>DirectAdmin server</li>
  <li>PHP-FPM</li>
  <li>PHP 7.2.10 (FPM)</li>
  </ul>