phpファイルを正常に読み込まない問題
MR
https://gitlab.com/karasu97/ansible-httpd/-/merge_requests/12
エラー対処録
問題の切り分け:エラー①
nginx
アクセスログを確認
下記のアクセスログによると、FastCGIの起動に関するエラーを発出しているため、Nginx->FastCGI/PHP関連の設定を行っているnginx.conf
の記載にミスがあると推測した。
# cat /var/log/nginx/error.log
2023/01/12 01:08:31 [error] 41568#41568: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: [client-ip], server: _, request: "GET /wp-config.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "[server-ip]"
# cat /var/log/nginx/access.log
仮説1:php-fpmの起動に失敗している。
下記のログよりPHP-FPMの起動は問題ない。
$ cat /var/log/php-fpm/error.log
[12-Jan-2023 22:59:46] NOTICE: fpm is running, pid 45256
[12-Jan-2023 22:59:46] NOTICE: ready to handle connections
[12-Jan-2023 22:59:46] NOTICE: systemd monitor interval set to 10000ms
原因:配置したwordpress.confが読み込まれていない
[ip]/readme.html
へアクセスしたところ、こちらも読み込めていなかったため、設定した$document_root
が適切に設定できていないことを疑った。また上記の設定を記述したwordpress.conf
が読み込めていない可能性が高いと推察した。
修正
問題の切り分け:エラー②(パッケージの依存エラー)
nginx
アクセスログを確認
依然としてphp
ファイルへの接続は確認できない。
2023/01/13 00:12:09 [error] 46552#46552: *3 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: [client_ip], server: example.com, request: "GET /wp-config.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "[ip]"
2023/01/13 00:12:09 [error] 46552#46552: *3 FastCGI sent in stderr: "PHP message: PHP Warning: preg_match(): Compilation failed: unrecognised compile-time option bit(s) at offset 0 in /var/www/public_html/wordpress/wp-includes/load.php on line 43PHP message: PHP Warning: preg_replace(): Compilation failed: unrecognised compile-time option bit(s) at offset 0 in /var/www/public_html/wordpress/wp-includes/functions.php on line 6046" while reading response header from upstream, client: [client_ip], server: example.com, request: "GET /wp-config.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "[ip]"
原因
根本的な原因は不明だったが、以下の記事を参考に試行錯誤した。
どうやらコンパイル時に何らかのエラーが発生していたため、パッケージの依存関係の問題であった。上の記事ではUbuntu系で使用されているlibpcre
のバージョンアップを試みたところ改善が見られた、とのこと。
対策
本環境でも、以下の設定をアップグレードを実施した。
$ yum list installed | grep pcre
$ yum upgrade pcre.x86_64 pcre2.x86_64 pcre2-syntax.noarch
pcre2-10.37-5.el9_0.x86_64 -> pcre2-10.40-2.el9.x86_64
pcre2-syntax-10.37-5.el9_0.noarch -> pcre2-syntax-10.40-2.el9.noarch
解決
他に講じた対策
/etc/php-fpm.d/www.conf
を確認したところ、listen.acl_users
にnginxユーザでのPOSIXアクセコントロールは実現されているため、listen.owner
やlisten.group
の設定は不要である。listen
はsock
を活用して、NginxからPHP-FPMへの接続を試みており、TCPでの通信より速度の面で優れている。
user = nginx
group = nginx
#listen = 127.0.0.1:9000
listen = /run/php-fpm/www.sock
;listen.owner = apache
;listen.group = apache
;listen.mode = 0660
listen.acl_users = apache,nginx
Edited by Lucifer