Skip to main content

How to Fix PHP Upload Error Code 6 (UPLOAD_ERR_NO_TMP_DIR) on Nginx with PHP-FPM

dsada

PHP upload error code 6 means UPLOAD_ERR_NO_TMP_DIR. This happens when PHP cannot find or write to the temporary upload directory.

Recommended Fix for Nginx + PHP-FPM

Since the server uses Nginx with PHP-FPM, the upload temporary directory must be writable by the PHP-FPM pool user, not necessarily by the Nginx user.

1. Check the PHP-FPM user

ps aux | grep php-fpm

Common users are nginx, apache, or a custom PHP-FPM pool user.

2. Create a dedicated temp directory for PHP 8.4

sudo mkdir -p /var/opt/remi/php84/tmp

If PHP-FPM runs as nginx, run:

sudo chown nginx:nginx /var/opt/remi/php84/tmp
sudo chmod 770 /var/opt/remi/php84/tmp

If PHP-FPM runs as apache, run:

sudo chown apache:apache /var/opt/remi/php84/tmp
sudo chmod 770 /var/opt/remi/php84/tmp

3. Update php.ini

Edit the PHP 8.4 ini file and set:

upload_tmp_dir = /var/opt/remi/php84/tmp
sys_temp_dir = /var/opt/remi/php84/tmp

4. Restart services

sudo systemctl restart php84-php-fpm
sudo systemctl restart nginx

5. If SELinux is enabled

Check SELinux status:

getenforce

If it returns Enforcing, apply the correct context:

sudo chcon -R -t httpd_sys_rw_content_t /var/opt/remi/php84/tmp

Summary

Nginx does not directly handle PHP uploads. PHP-FPM handles them, so the temporary upload directory must be writable by the PHP-FPM pool user. Creating a dedicated directory such as /var/opt/remi/php84/tmp is cleaner than relying on the system /tmp directory.

Tags