Missing a Temporary Directory’ Error in WordPress: Causes and Solution on Servers with VestaCP

Below you will find a step-by-step tutorial to fix the “Missing a Temporary Folder” error in WordPress and the issue of not being able to upload images or files. This specific case occurred on a server with VestaCP, but the steps are similar on any hosting with open_basedir configurations and folder permissions.

1. Problem Description

When trying to upload an image in WordPress (under MediaAdd New), the error appears:

“Missing a temporary folder”
(or in some versions, “The uploaded file could not be moved to…”)

Also, in the server error logs, messages like the following can be seen:

sqlCopyPHP Warning:  Unknown: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s)...
File upload error - unable to create a temporary file in Unknown on line 0

It may also be that after fixing open_basedir, a new error appears:

“The uploaded file could not be moved to wp-content/uploads/…”

This indicates a permissions problem in the uploads folder.


2. Main Causes

  1. open_basedir restriction: PHP is trying to use /tmp (or some temporary folder), but it is not included in the list of directories allowed by open_basedir.
  2. Permissions on the uploads folder: The user running PHP/Apache (for example, www-data) does not have write permissions on wp-content/uploads.

3. Two-Part Solution

3.1. Add :/tmp to the open_basedir directive

On many servers with VestaCP, the open_basedir directive is not defined directly in /etc/php/7.x/apache2/php.ini, but rather in domain-specific configuration files. To find them:

  1. Search where the open_basedir directive is defined
    • Connect via SSH and check the domain configuration folder:bashCopycd /home/USER/conf/web grep -Ri open_basedir .
    • In our example, the user is client and the domain is client.com.mx. Files found include:arduinoCopy/home/client/conf/web/client.com.mx.apache2.conf /home/client/conf/web/client.com.mx.apache2.ssl.conf
    • Inside these files, a line like this was found:iniCopyphp_admin_value open_basedir /home/client/web/client.com.mx/public_html:/home/client/tmp
  2. Edit to include :/tmp
    • Open each file with an editor (e.g., nano) and modify the line:iniCopyphp_admin_value open_basedir /home/client/web/client.com.mx/public_html:/home/client/tmp to this:iniCopyphp_admin_value open_basedir /home/client/web/client.com.mx/public_html:/home/client/tmp:/tmp
    • Save the changes.
  3. Restart the service
    • If you use Apache with mod_php:bashCopysystemctl restart apache2
    • If you use PHP-FPM:bashCopysystemctl restart php7.2-fpm
    • Adjust the 7.2 version as appropriate.
  4. Verify with phpinfo()
    • Create or check info.php (inside your site) with:phpCopy<?php phpinfo();
    • Access https://yourdomain.com/info.php and locate “open_basedir” in the “PHP Core” section.
    • Make sure the Local Value includes :/tmp.

This will remove the “open_basedir restriction in effect” error and the “Missing a temporary folder” warning. PHP will be able to use /tmp without restrictions.


3.2. Adjust permissions on the uploads folder

After fixing the open_basedir part, you might still see an error like:

“The uploaded file could not be moved to wp-content/uploads/2025/01.”

This indicates that the user running PHP/Apache (for example, www-data) does not have write permissions on wp-content/uploads (and subdirectories).

  1. Identify the Apache/PHP user
    • On Ubuntu/Debian, it is usually www-data. On CentOS, it’s often apache.
    • If you use VestaCP with PHP-FPM, sometimes it runs as the account user (e.g., client). But in this case, Apache/PHP was running as www-data.
  2. Inside those files, a line like this was found:iniCopyphp_admin_value open_basedir /home/cliente/web/cliente.com.mx/public_html:/home/cliente/tmp
  3. Edit to include :/tmp
    • Open each file with an editor (for example, nano) and modify the line:iniCopyphp_admin_value open_basedir /home/cliente/web/cliente.com.mx/public_html:/home/cliente/tmp so it looks like this:iniCopyphp_admin_value open_basedir /home/cliente/web/cliente.com.mx/public_html:/home/cliente/tmp:/tmp
    • Save the changes.
  4. Restart the service
    • If you use Apache with mod_php:bashCopysystemctl restart apache2
    • If you use PHP-FPM:bashCopysystemctl restart php7.2-fpm
    • Adjust the 7.2 version as appropriate.
  5. Verify with phpinfo()
    • Create or check info.php (inside your site) with:phpCopy<?php phpinfo();
    • Access https://yourdomain.com/info.php and locate “open_basedir” in the “PHP Core” section.
    • Make sure the Local Value includes :/tmp.

This will remove the “open_basedir restriction in effect” error and the “Missing a temporary folder” warning. PHP will be able to use /tmp without restrictions.


3.2. Adjust permissions on the uploads folder

After fixing the open_basedir part, you might still see an error like:

“The uploaded file could not be moved to wp-content/uploads/2025/01.”

This indicates that the user running PHP/Apache (for example, www-data) does not have write permissions on wp-content/uploads (and its subdirectories).

  1. Identify the Apache/PHP user
    • On Ubuntu/Debian, it’s usually www-data. On CentOS, it’s typically apache.
    • If you use VestaCP with PHP-FPM configured to use the same user as the account owner (e.g. cliente), you don’t need to change permissions to www-data. But if the process runs as www-data, then WordPress needs www-data to have permissions.
  2. Assign correct ownership and permissions
    • From your WordPress root:bashCopycd /home/cliente/web/cliente.com.mx/public_html/wp-content
    • Change the ownership of the uploads folder:bashCopychown -R www-data:www-data uploads (Replace www-data:www-data with the actual user/group running PHP, if different.)
    • Set recommended permissions:bashCopyfind uploads -type d -exec chmod 755 {} \; find uploads -type f -exec chmod 644 {} \;
  3. Test uploading a file
    • Go to WordPressMediaAdd New and upload an image or PDF.
    • If permissions are correct, WordPress will be able to move the file from the temporary folder to wp-content/uploads/YYYY/MM.

4. Conclusion

To fix the error “Missing a temporary folder” or “The uploaded file could not be moved…” in WordPress, check these two points:

  1. Include /tmp in open_basedir: edit your domain’s configuration files so that open_basedir allows :/tmp, then restart PHP/Apache.
  2. Permissions on uploads: make sure the wp-content/uploads folder (and subfolders) belong to the user running PHP and have write permissions (directories 755, files 644).

This way, your WordPress will be able to:

  • Create temporary files without open_basedir restrictions.
  • Move uploaded files to the uploads folder without permission errors.

And that’s it! You will no longer see the “Missing a temporary folder” or “The uploaded file could not be moved…” message, and you’ll be able to upload files normally in WordPress.