解决一次Typecho站点的502
环境
- PHP 7.4
- Nginx 1.19
- MySQL 5.6
- Typecho v1.1-17.10.30-release
访问任何/index.php/action/someAction?args
都会502,最开始猜想是伪静态的问题,但是转念一想伪静态导致的是404,排除掉。
迁移前后Nginx、Mysql、PHP的版本都不一样,由于只是弄着玩的,安装太耗时间,不打算一个一个实验,直接将Typecho更新到v1.2-dev,php到8.0。
在问题之前的404
2022/01/21 18:38:27 [error] 388901#0: *43 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: open_basedir restriction in effect. File(/www/wwwroot/Typecho/index.php) is not within the allowed path(s): (/www/wwwroot/private_Typecho/:/tmp/) in Unknown on line 0PHP message: PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0Unable to open primary script: /www/wwwroot/Typecho/index.php (Operation not permitted)" while reading response header from upstream, client: 103.97.200.98, server: x.std.moe, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/tmp/php-cgi-74.sock:", host: "x.std.moe"
.user.ini
中设置的open_basedir=
与当前路径不匹配,原因是我直接复制粘贴了迁移站点。
更改后,可以正常访问文章和后台界面。
问题1
*402 FastCGI sent in stderr: "PHP message: PHP Fatal error: Declaration of Title_Plugin::label($value) must be compatible with Typecho\Widget\Helper\Form\Element::label(string $value): Typecho\Widget\Helper\Form\Element in /www/wwwroot/Typecho/usr/plugins/Handsome/Plugin.php on line 1220"
原因是我迁移前是php5.6,迁移后是php7.4,不严谨的语法会直接fatal error..
遂更新主题至最新版本。
问题2
*258 FastCGI sent in stderr: "PHP message: PHP Warning: Array to string conversion in /www/wwwroot/Typecho/var/Typecho/Http/Client.php on line 306" while reading response header from upstream
导致502的元凶。这个error在将数组转换为字符串时抛出,例如:
$num = 9;
print("$num");
// 9 ..
$arr = [1,2,3,4,5];
print("$arr")
// Err! Array to string conversion ..