本博客站点用的是 WordPress,最近进入后台的时候,老是提示使用的 PHP 7.4 版本太老,最好更新到 8 以上。老夫当然从善如流,立刻着手。
首先当然是加了个大众广泛使用的软件源(LC_ALL=C.UTF-8 sudo add-apt-repository ppa:ondrej/php -y 然后 sudo apt update),很可惜的是加完以后 apt 仍然报找不到更新版本的 PHP。
又查了一下,哦豁,原来是 PHP 嫌弃操作系统 Ubuntu 18.04 太老,已经不再提供对应的安装包,不仅如此,而且看上去连 20.04 也已经被抛弃了。好吧,一步一步来。先升到 20.04 看看?出奇顺利,升级结束后立刻尝试访问博客,正常得不像话,就跟没有升级过一样。胆子于是大了点。继续根据服务商的说明把 Ubuntu 从 20.04 往 22.04 上升。完成后先是感觉又很成功,系统启动正常。但随即尝试访问博客,呵呵,它就 502 了。事已至此,先吃饭吧。
饭后继续。升级系统似乎把 PHP 7.4 有关的某些部分搞掉了,所以才 502。咱原本就是要升级 PHP 的,所以倒也不算什么大问题。于是当即再次执行前述的软件源添加命令,然后 sudo apt install php8.4 php8.4-fpm php8.4-mcrypt php8.4-mysql php8.4-xml php8.4-zip,好像就这些吧。然后去到 /etc/php/8.4/fpm 下,把 pool.d/www.conf 文件里的 user、group 以及 listen.owner 和 listen.group 修正成实际情况,pm.max_requests 稍微调了调;又打开 php.ini 把 max_execution_time 也调了下,最主要的还是 post_max_size 和 upload_max_filesize 这俩值,太小了不够用;最后看了一眼 php-fpm.conf 文件,发现什么都不需要动。执行 sudo systemctl restart nginx php-fpm 后尝试访问站点,嗯,502 消失了,代之以“此站点遇到了致命错误。”
页面相当干净,别的有用信息统统没有。只好去把 wp-config.php 里的 WP_DEBUG 开关打开,刷新页面。当即发现 crayon-syntax-highlighter 扩展可能是最重要的那个问题源(问题一),屏蔽了它再刷新,原来的正常页面内容就开始出现了,但夹杂着各种错误信息。就像泄洪一般,一大片的 Notice、Deprecated、Warning。
计有,页面顶部出现以下问题。问题二:
Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the jalw_i18n domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /…/wp-includes/functions.php on line 6121
查资料,此问题多由插件/主题带来。经测试,禁用 JS Archive List 插件后,此提示即告消失。在 AI 辅助下尝试修复未果。
接着是连续五条这个(问题三),
Deprecated: Creation of dynamic property Hybrid_Layout::$name is deprecated in /…/wp-content/themes/stargazer/library/inc/class-layout.php on line 162
这是一个本博客当前使用的主题,已久不更新。打开该文件,将以下成员声明放到类的开头,
|
1 2 3 4 5 6 7 8 |
/** * The layout name/slug. * * @since 4.0.0 * @access public * @var string */ public $name = ''; |
即可解决(这是被第二个解决的问题,根由是 PHP 不再建议使用动态属性)。
还有一条是这样(问题四),
Warning: foreach() argument must be of type array|object, string given in /…/wp-includes/class-wp-theme-json.php on line 2101
不知道问题出在哪儿。
接下来是页面内出现最多的一组,总有十几次(问题五),
Warning: compact(): Undefined variable $post_id in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $order in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $meta_key in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $featured in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $attachment in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $scan in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $scan_raw in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $callback in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $default in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $split_content in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $size in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $srcset_sizes in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $link in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $link_class in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $image_class in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $image_attr in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $width in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $height in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $before in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $after in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $min_width in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $min_height in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $caption in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $meta_key_save in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $thumbnail_id_save in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $cache in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $format in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $echo in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $custom_key in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $default_size in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $the_post_thumbnail in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $image_scan in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $default_image in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $order_of_image in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
Warning: compact(): Undefined variable $link_to_post in /…/wp-content/themes/stargazer/library/ext/get-the-image.php on line 298
当我把第 298 行代码从 $key = md5( serialize( compact( array_keys( $this->args ) ) ) ); 改为 $key = md5( serialize( $this->args ) ); 后,这些警告消失。由于它太碍眼,所以是第一个被解决掉的。
上述共计五个问题,三和五已经解决掉,二和四未解决,不过它们仅是告警类信息,把 WP_DEBUG 关闭后是看不到的。第一个问题最严重,是那个代码高亮的插件引发,抽空了再看吧。
