How do I set the upload_tmp_dir?


  • Applies to: All DV
    • Difficulty: Medium
    • Time Needed: 10
    • Tools Required: SSH, root access, vi knowledge
  • Applies to: Grid
    • Difficulty: Medium
    • Time Needed: 10
    • Tools Required: SSH, Account Center access, vi knowledge

Overview

The temporary directory is used for storing files when a file is uploaded. This directory must be writable by whichever user PHP is running as. If not specified, PHP will use the system's default.

If the directory specified is not writable, PHP falls back to the system default temporary directory. If open_basedir is on, then the system default directory must be allowed for an upload to succeed.

READ ME FIRST

This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by (mt) Media Temple. Please take a moment to review the Statement of Support.

Symptom

I'm getting an upload_tmp_dir error when using PHP. How do I fix this error?

You receive an upload_tmp_dir error when you upload files through PHP.

Solution

This can be done by adding the following line in your php.ini file:

upload_tmp_dir /tmp

Alternatively, if you wish to specify upload_tmp_dir for just one domain, add the following line in the domain's vhost.conf file.

<Directory /path/to/vhosts/example.com/httpdocs>
php_admin_value upload_tmp_dir /tmp
</Directory>

Once the changes have been made to the file, run the command below to make the changes take affect:

websrvmng -a -v

Resources


Overview

The temporary directory is used for storing files when a file is uploaded. It is possible that uploads will sometimes fail if the global tmp (temporary) directory becomes full before it is emptied. If this is the case, you may receive a "disk quota exceeded" error while attempting to upload using PHP. The solution for this is to set a local tmp directory using the php.ini file.

READ ME FIRST

This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by (mt) Media Temple. Please take a moment to review the Statement of Support.

Instructions

1. Either connect to your Grid server using SSH, or simply use the File Manager located in the Account Center.

2. The php.ini file is a PHP configuration file. It is read when PHP starts up and determines many aspects of PHP handling. It's located in the etc directory. Navigate to /home/00000/etc/, replacing '0000' with your site id.

3. Open the php.ini file using the editor in the file manager or using a text editor such as vi/vim. Add the following line to the file, replacing '00000' with your site id:

upload_tmp_dir = /home/00000/data/tmp

4. Save the file and verify that permissions are set to 777. If you are using SSH, you will need to use the chmod command to set the privileges to 1777. The '1' is known as the "sticky bit" and prevents the file from being deleted or renamed, while still allowing total read, write, and execution privileges. 

SSH (while still in the etc directory): chmod 1777 php.ini

Grid file manager:

 

 You should now have a local tmp directory set. To verify that it is working properly, attempt to upload using PHP. 

Resources