php-fpm修正User和Group權限

今日試著將OS升從Debian 8升級到9,亦更新php相關套件的版本之後,遇到網站無法開啟的狀況。
先查詢了nginx的error.log看php7.4-fpm.scok有權限錯誤的訊息:

2020/03/14 12:15:08 [crit] 902#902: *27 connect() to unix:/var/run/php/php7.4-fpm.sock failed (13: Permission denied) while connecting to upstream

先是修改了/var/run/php/php7.4-fpm.sock的Owner,因為我的nginx使用者與群組並非是預設的www-data,但是修改Owner並重啟php-fpm服務後發現仍會被改回原有的權限。再查詢資料後,其實要修改 php-fpm設定檔內容才對正確的方式,修改user和group指派的內容而非預設的www-data,再重啟php-fpm服務即可。

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = www-data
group = www-data
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
;                 mode is set to 0660
listen.owner = www-data
listen.group = www-data