Skip to content

PHP-FPM uploads failing because /tmp is mounted noexec

How a noexec mount on /tmp breaks PHP file uploads and a subset of WordPress plugins on a cPanel server, and how to either move PHP's temp directory or remount with safer permissions.

A hardened cPanel server mounts /tmp with noexec to block tmp-staged exploits. The hardening is generally good. The side effect is that any PHP code that writes a file into /tmp and then tries to execute it — common in some image-processing libraries, several WordPress plugins, and Composer’s installer — fails with Permission denied. The fix is not to remove noexec; the fix is to give PHP an executable temp directory of its own.

What’s happening

PHP’s upload_tmp_dir, sys_temp_dir, and session.save_path all default to /tmp if not explicitly set. With /tmp mounted noexec, files placed there are not executable as scripts or binaries. Most uploads work fine — they go to /tmp only briefly before being moved to the destination. But code that creates a temp file, writes a script to it, and exec()s it (Imagemagick’s policy.xml workarounds, some PDF generators) hits Permission denied and surfaces a generic 500.

How to verify

Check the mount and the PHP temp settings:

mount | grep tmp
findmnt /tmp
grep -E "^(upload_tmp_dir|sys_temp_dir|session.save_path)" /opt/cpanel/ea-php82/root/etc/php.ini
cat /var/cpanel/users/<user>/php.ini 2>/dev/null
ls -ld /home/<user>/tmp 2>/dev/null

If /tmp is mounted with noexec and upload_tmp_dir is unset (so it defaults to /tmp), uploads to apps that need exec rights will fail.

The fix

  1. Per account, create a writable temp directory in the user’s home: mkdir -p /home/<user>/tmp && chown <user>:<user> /home/<user>/tmp && chmod 750 /home/<user>/tmp.
  2. Point PHP at it via MultiPHP INI Editor > Basic Mode > pick the user > add:
    upload_tmp_dir = /home/<user>/tmp
    sys_temp_dir = /home/<user>/tmp
    Leave session.save_path on its own subdirectory if sessions are used.
  3. Reload the FPM pool: systemctl reload ea-php82-php-fpm.
  4. Confirm: have a PHP probe in the customer’s docroot return sys_get_temp_dir() and ini_get('upload_tmp_dir'). Both should point at the new location.
  5. Validate with a real upload from the application that was failing. The temp file is created, executed if needed, then moved to its destination — all within the account’s home which is not noexec.
  6. Resist the urge to remount /tmp as exec. The hardening is valuable for the whole server; the per-account workaround keeps the boundary in place.

For environments where /tmp is hardened and PHP applications need exec, Stack Harbor sets per-account temp directories during onboarding under cPanel server administration.