PHP Development Note.

文章中紀錄在使用PHP項目開發中遇到的錯誤問題,但是這些問題在開發中經常碰到的日常問題,沒有必要老是去看文檔之類的解決問題,所以都總結到改文檔

Uncaught Swoole\Error: API must be called in the coroutine in

connect() to unix:/run/php/php8.1-fpm.sock failed (13: Permission denied) while connecting to upstream

解決方案:

查看該socket套接字的權限:

ls -l /run/php/php8.1-fpm.sock

發現權限是:

srw-rw---- 1 www-data www-data 0 Sep  6 15:04 /run/php/php8.1-fpm.sock

查看**php-fpm的配置文件,由於使用的php-fpm** pool管理,所以要查看pool.d

中的配置如下:

; 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. The owner
; and group can be specified either by name or by their numeric IDs.
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = ubuntu
;listen.owner = www-data
listen.group = ubuntu
;listen.owner = www-data

FILE NOT FOUND

今日在安裝部署PHP8.1-FPM的時候,nginx配置沒有問題,但是頻繁出現FILE NOT FOUND的提示。nin

nginx的日誌提示:“`[error] 4805#4805: *3 FastCGI sent in stderr: “Primary script unknown” while reading response header from upstream, client: 141.101.86.98, server: ethanwong.online, request: “GET / HTTP/1.1”, upstream: “fastcgi://unix:/run/php/php8.1-fpm.sock:”, host: “ethanwong.online”“`。

解決方案是修改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

修改為:

; 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 = ubuntu
group = ubuntu

其中ubuntu 是當前登錄的Ubuntu系統的子用戶。

修改之後重啟php8.1-fpm問題就解決了。

Leave a Reply

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