Skip to content

Fixed the ‘failed to open stream: Permission denied’ error of visiting WordPress on CentOS 8

  • by

Fixed the “failed to open stream: Permission denied in Unknown on line 0” error of visiting WordPress on CentOS 8.

1. The “failed to open stream: Permission denied in Unknown on line 0” Error

An “access denied” error occurred of first-time visiting WordPress , which had been set up with php and Nginx on a local CentOS 8:
fig-01

and the corresponding error log:

2020/11/04 20:42:03 [error] 1446#0: *3 FastCGI sent in stderr: "PHP message: PHP Warning:  Unknown: failed to open stream: Permission denied in Unknown on line 0Unable to open primary script: .../wordpress/index.php (Permission denied)" while reading response header from upstream, client: ::1, server: _, request: "GET /wordpress/ HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "localhost"

After online searching, I found a post of a similar issue from (13: Permission denied) while connecting to upstream:nginx, which led me to an Aha moment: the issue is not due to misconfigurations of php-fpm nor Nginx, but the SELinux. After it was disabled, the issue had been solved.

2. Some Thoughts about Fixing the Issue

Cause-finding is always a tricky one: logs are are usually helpful, but this time log messages are actually misleading. “Permission denied” made me think of configuration errors, and I had tried:

  • rechecking user/group, mode configurations of php-fpm
  • rechecking php configurations of Nginx
  • rechecking user/group settings of WordPress directories
  • switching a local listening port or a unix sock to communicate with php-fpm back and forth

It took me a week or two intermittently to go through these trials, but all were without luck. I probably couldn’t solve it if I hadn’t found the post.

After all failed trials, I knew I probably need to “think outside of the box”, but it’s difficult because I don’t have a ground truth to to narrow the search space.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *