You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu环境下Moodle 4.x命令行安装失败求助

Ubuntu下Moodle 4.x命令行安装失败(/lib/installlib.php第187行)

我正遵循Moodle命令行安装指南在Ubuntu上部署Moodle 4.x,但在/lib/installlib.php文件的第187行执行失败。我已确认数据库连接信息(用户名、密码等)填写正确,此前一直通过Web界面完成Moodle安装,想咨询是否有人成功通过命令行完成Moodle 4.x的安装?

相关代码片段如下:

/**
 * This is in function because we want the /install.php to parse in PHP4
 *
 * @param object $database
 * @param string $dbhost
 * @param string $dbuser
 * @param string $dbpass
 * @param string $dbname
 * @param string $prefix
 * @param mixed $dboptions
 * @return string
 */
function install_db_validate($database, $dbhost, $dbuser, $dbpass, $dbname, $prefix, 
$dboptions) {
    if (!preg_match('/^[a-z_]*$/', $prefix)) {
        return get_string('invaliddbprefix', 'install');
    }
    try {
       try {
           $database->connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);
       } catch (moodle_exception $e) {
           // let's try to create new database
            if ($database->create_database($dbhost, $dbuser, $dbpass, $dbname, 
$dboptions)) {
               $database->connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, 
$dboptions);
            } else {
                throw $e;
            }
       }
       return '';
    } catch (dml_exception $ex) {
        $stringmanager = get_string_manager();
        $errorstring = $ex->errorcode.'oninstall';
        $legacystring = $ex->errorcode;
        if ($stringmanager->string_exists($errorstring, $ex->module)) {
            // By using a different string id from the error code we are separating 
   exception handling and output.
            $returnstring = $stringmanager->get_string($errorstring, $ex->module, $ex->a);
            if ($ex->debuginfo) {
                $returnstring .= '<br />'.$ex->debuginfo;
            }

            return $returnstring;
        } else if ($stringmanager->string_exists($legacystring, $ex->module)) {
        // There are some DML exceptions that may be thrown here as well as during 
normal operation.
        // If we have a translated message already we still want to serve it here.
        // However it is not the preferred way.
        $returnstring = $stringmanager->get_string($legacystring, $ex->module, $ex->a);
        if ($ex->debuginfo) {
            $returnstring .= '<br />'.$ex->debuginfo;
        }

            return $returnstring;
        }
        // No specific translation. Deliver a generic error message.
        return $stringmanager->get_string('dmlexceptiononinstall', 'error', $ex);
    }
}

内容的提问来源于stack exchange,提问作者Energetic Pixels

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 17:56:18