When I used Homebrew to install a package, it updated my PHP version, causing issues accessing PHP scripts via my Nginx server at localhost:8080/index.php. After the update, this access stopped working.
To identify the root cause, running tail -n 50 /opt/homebrew/var/log/nginx/error.log
reveals an error message:
2023/12/12 05:16:10 [error] 12805#0: *5 FastCGI sent in stderr: "PHP message: PHP Warning: PHP Request Startup: Failed to open stream: Operation not permitted in Unknown on line 0; Unable to open primary script: /Users/workmac/documents/work-web-nginx/index.php (Operation not permitted)" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost:8080"
The issue appears to stem from the PHP-FPM configuration. When a new PHP version is installed, it’s crucial to manually adjust the user and group settings in php-fpm.conf
to align with the PHP scripts, as they default to “_www”.
To locate the php-fpm.conf
file on a Mac, you can use the command sudo find / -type f -name "php-fpm.conf" 2>/dev/null
. In my case, it’s located at /opt/homebrew/etc/php/8.3/php-fpm.d/www.conf
.
After finding this file, locate and modify the user
and group
fields to match the user and group for the PHP scripts. You can find this information by running ls -l
.