This article aims to outline causes and solutions for the "Unable to create lock file: Bad file descriptor" error in the Apache error log which causes 500 internal server errors on PHP websites.
# tail -n0 -f /var/log/apache2/error_log
[:error] [pid 11817] [client 192.0.2.0:52413]
Fatal Error Unable to create lock file: Bad file descriptor (9)
[core:error] [pid 11817] [client 192.0.2.0:52413]
End of script output before headers: index.php
One cause of this error is the /tmp directory having incorrect permissions:
# stat -c %a /tmp
These permissions will cause Apache to be unable to create session files if /tmp is configured in PHP to store them.
If /tmp does not have 1777 permissions, this issue can be corrected with the following command:
chmod -v 1777 /tmp /var/tmp