I wonder where the tmp dir is set in the code of Drupal 8. Indeed the upload_tmp_dir value is not set in the php.ini and I have no access to change it.

Where in the code the value is defined and change it?

  • 1
    Do you have any errors on admin/reports/status ? – mpdonadio Dec 4 '19 at 14:06

The logic for finding the proper OS temp directory is in FileSystem::getOsTemporaryDirectory. This will try to use upload_tmp_dir, otherwise default back to an OS value, like /tmp.

This get used in file_directory_temp(). If you read this function, you will see that the config value gets read first, and then it will try to get the OS default.

Personally, I set the filesystem paths in my settings.local.php file, so I can have a different value per environment, eg

$config['system.file']['path']['temporary'] = '/var/www/staging/tmp';

You also need to ensure that the file is writable by the webserver. Securing file permissions and ownership is the canonical reference on this, but in short something like

sudo chown -R www-data:www-data /var/www/staging/tmp
sudo find /var/www/staging/tmp -type f -exec chmod 664 {} \;
sudo find /var/www/staging/tmp -type d -exec chmod 2775 {} \;

will work.


You can find the setting in /admin/config/media/file-system. If you need that in php, you can use code like


The correct config for your tmp dir is system.file.path.temporary. Check it in the UI with config-sync of simple config "system.file". Check class FileUploadResource for an example.

  • 1
    To clarify this: It's not set in "code", it's a configuration of your Drupal System. – Rainer Feike Dec 4 '19 at 10:06
  • I have tried to modify the value of temporary dir with the UI in /admin/config/media/file-system but it doesn't work it's for that i need to change it in the code of drupal 8, it is possible ? Thanks in advance – user3685256 Dec 4 '19 at 10:18
  • You need an editable config like so: \Drupal::configFactory()->getEditable('user.settings') ->set('notify.status_activated', FALSE) ->save(); – Rainer Feike Dec 4 '19 at 10:20
  • Ok thanks but where i put this line of code ? thanks in advance – user3685256 Dec 4 '19 at 10:22
  • 1
    That is a problem with your server configuration – Kevin Dec 4 '19 at 14:31

You are wanting to hack the core. Which is evil. You simply can set another temporary directory on https://example.com/admin/config/media/file-system.

enter image description here

Via Drush.

$ drush -y config:set system.file path.temporary /Users/norman/Sites/temp

Alternatively but also quite evil is overriding PHP config from your settings.php. But note that some server setups may block PHP script files containing ini_set() calls, resulting in a WSOD.

ini_set('upload_tmp_dir', '/tmp');

  • When i try to change temporary folder by UI at admin/config/media/file-system. this doesn't work, i dont know why .. this is the problem :/ The upload_tmp_dir is not defined and not accessible and init_set dont work beacause this variable cant be change by init_set – user3685256 Dec 4 '19 at 11:01
  • 1
    That is a problem with your server configuration – Kevin Dec 4 '19 at 14:32
  • something to do ? – user3685256 Dec 5 '19 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.