The mkdir(): Permission denied error in phpMyAdmin typically occurs when PHP attempts to create a temporary directory without effective write permissions. In my environment, the cause was not just chmod, but a combination of inconsistent ownership and PHP-FPM path policies.
Observed symptom#
- Upload/import in phpMyAdmin failing;
mkdir permission deniederror message;- Operations depending on temporary directories not completing.
Step-by-step diagnosis#
Find the FPM pool user:
ps aux | grep php-fpm
Validate the temporary path used by PHP:
php -i | grep -E 'upload_tmp_dir|sys_temp_dir|open_basedir'
Validate directory permissions:
ls -ld /tmp
ls -ld /var/lib/php/sessions
Applied fix#
In my case, I corrected the owner/group of the working directory and ensured compatible permissions for the execution user:
chown -R www-data:www-data /var/lib/php/sessions
chmod 1733 /var/lib/php/sessions
If the upload temp directory is customized to another path, adjust that path accordingly.
Open_basedir verification#
Even with correct permissions, open_basedir can block access to the directory. Validate and include the allowed path in the pool/site configuration.
Example adjustment (conceptual):
php_admin_value[open_basedir] = /home/site/web:/tmp:/var/lib/php/sessions
After the change:
systemctl restart php8.1-fpm
systemctl reload nginx
Final validation#
- Reopen phpMyAdmin;
- Attempt a small import and then a larger file;
- Review PHP-FPM and webserver logs to confirm the absence of new denies.
Log evidence collected during diagnosis#
From PHP-FPM:
journalctl -u php8.1-fpm -n 120 --no-pager | grep -Ei 'mkdir|permission|open_basedir'
From Nginx/Apache:
grep -Ei 'phpmyadmin|permission denied|mkdir' /var/log/nginx/error.log | tail -n 50
grep -Ei 'phpmyadmin|permission denied|mkdir' /var/log/apache2/error.log | tail -n 50
These snippets are included in the incident dossier to prove the root cause and the corrective action applied.
Additional cases i've handled#
Directory exists, but SELinux blocks writing#
When SELinux is set to Enforcing, POSIX permissions might appear correct while the operation still fails.
Validation:
sestatus
ausearch -m avc -ts recent | tail -n 30
Context Fix (example):
semanage fcontext -a -t httpd_sys_rw_content_t '/var/lib/php/sessions(/.*)?'
restorecon -Rv /var/lib/php/sessions
Session in a full partition#
If the temp/sessions partition is out of space or inodes, the mkdir error might be masked.
df -h
df -i
Preventive checklist#
- Keep
upload_tmp_direxplicit in multi-PHP environments; - Standardize owner/group for session directories;
- Review
open_basedirin new pools/sites; - Monitor FPM logs after panel or PHP upgrades.
Production takeaways#
mkdir permission denied in phpMyAdmin requires a diagnosis of real PHP execution (user, directory, and policy). Simply adjusting to chmod 777 masks the problem and increases security risk. The correct fix is to align owner, permissions, and path restrictions.
Was this article helpful?
Leave a quick reaction to help prioritize future technical guides:
This post is licensed under CC BY-NC.



Comments
Join the discussion below.
0 comments