When running XAMPP on Linux, SELinux or AppArmor may block PHP from accessing the session directory, causing the error:
session_start(): open(session_file, O_RDWR) failed: Permission denied (13)
session_start(): Failed to read session data: files (path: /opt/lampp/temp/)
SELinux (Security-Enhanced Linux) enforces security policies that can restrict access to session files.
Run:
sestatus
If it returns:
SELinux status: enabled
SELinux mode: enforcing
SELinux is blocking access to /opt/lampp/temp/.
Since PHP sessions are stored in /opt/lampp/temp/, grant the necessary SELinux permissions.
Run:
sudo journalctl -xe | grep AVC
or:
sudo grep "denied" /var/log/audit/audit.log
Look for entries related to /opt/lampp/temp/.
Run the following command:
sudo chcon -R -t httpd_sys_rw_content_t /opt/lampp/temp/
This assigns the correct SELinux context to allow Apache (httpd) to read and write session files.
If you're running Ubuntu or Debian, AppArmor may be blocking PHP.
Run:
sudo aa-status
If AppArmor is enforcing restrictions on /opt/lampp/temp/, switch it to complain mode:
sudo aa-complain /usr/sbin/apache2
sudo aa-complain /usr/sbin/php-fpm
sudo systemctl restart apache2
sudo systemctl restart php8.0-fpm
Test again to see if the session issue is resolved.
If SELinux still blocks access, temporarily disable it to confirm.
Run:
sudo setenforce 0
Then restart XAMPP:
sudo /opt/lampp/lampp restart
If sessions now work, then SELinux is the problem, and you should configure SELinux properly instead of disabling it permanently.
If SELinux/AppArmor is not the issue, fix the session folder permissions.
sudo chmod -R 770 /opt/lampp/temp/
sudo chown -R daemon:daemon /opt/lampp/temp/
For Apache on Linux:
sudo chown -R www-data:www-data /opt/lampp/temp/
Restart services and test again.
If the error persists, check logs:
sudo tail -f /opt/lampp/logs/error_logsudo tail -f /opt/lampp/logs/php_error_logsudo dmesg | grep php| Issue | Fix |
|---|---|
| SELinux blocking session directory | chcon -R -t httpd_sys_rw_content_t /opt/lampp/temp/ |
| AppArmor restricting access | aa-complain /usr/sbin/apache2 |
| Wrong folder permissions | chmod -R 770 /opt/lampp/temp/ |
| Incorrect ownership | chown -R daemon:daemon /opt/lampp/temp/ |
| Still not working? | setenforce 0 (temporary SELinux disable) |
By following these server-level fixes, you can resolve SELinux/AppArmor restrictions and restore PHP session functionality in XAMPP.