强制更新因PHP更新而无法启动的Nextcloud

2 min

language: ja bn en es hi pt ru zh-cn zh-tw

images.png

大家好,我是无能。

由于我一下子将PHP版本升级到了8.2.7,导致原本支持PHP8.0的Nextcloud无法启动了。

This version of Nextcloud is not compatible with PHP>=8.2.
You are currently running 8.2.7.

只显示了这些内容,即使尝试从CLI更新也无法进行CLI更新。

因此,我找到了一个伪装Nextcloud识别的PHP版本的方法。

位置在Nextcloud目录下的/nextcloud/lib/versioncheck.php。
※以下是已经更新过的代码。注释部分很长,已被删除。

<?php

declare(strict_types=1);

if (PHP_VERSION_ID < 80000) {
	http_response_code(500);
	echo 'This version of Nextcloud requires at least PHP 8.0<br/>';
	echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.';
	exit(1);
}

// Show warning if >= PHP 8.3 is used as Nextcloud is not compatible with >= PHP 8.3 for now
if (PHP_VERSION_ID >= 80300) {
	http_response_code(500);
	echo 'This version of Nextcloud is not compatible with PHP>=8.3.<br/>';
	echo 'You are currently running ' . PHP_VERSION . '.';
	exit(1);
}

问题就在这里。

if (PHP_VERSION_ID >= 80300) {

因为它在这里检查版本,请将其设置为与您安装的PHP版本相同或更高

在我的情况下,因为PHP版本是8.2.7,我将其更改如下:

if (PHP_VERSION_ID >= 80207) {

之后从CLI执行

sudo -u www-data php /var/www/html/cloud/occ update:check

就通过了。
请指定用户并设置正确的路径,以便occ能够启动。

虽然我一下子升级到了最新版本,但操作变得非常流畅,我认为结果是好的。
但是,这种设计是好是坏呢……
我觉得无论PHP版本如何,都应该默认允许更新,但我不清楚为什么会采用这种设计。

那么,下次再见。

Related Posts