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

Ubuntu 18.04服务器安装MCHostPanel遇权限拒绝问题如何解决?

问题:MCHostPanel安装后无法登录(权限错误)

在Ubuntu 18.04 64位VPS上安装GitHub的MCHostPanel后,无法使用登录凭据登录。查看apache2日志得到如下报错:

[Sat Jul 30 09:00:46.063745 2022] [php7:warn] [pid 444] [client mywebsite.com:62027] PHP Warning:  file_put_contents(data/users/jox.json): failed to open stream: Permission denied in /var/www/html/inc/lib.php on line 586, referer: http://mywebsite.com/install.php
[Sat Jul 30 09:00:46.063797 2022] [php7:warn] [pid 444] [client mywebsite.com:62027] PHP Warning:  file_put_contents(.installed): failed to open stream: Permission denied in /var/www/html/install.php on line 9, referer: http://mywebsite.com/install.php

管理员用户对应的data/users/jox.json文件未生成,项目GitHub Issues长期不活跃,寻求解决方法。

相关代码片段:
install.php第2-11行:

require_once 'inc/lib.php';

$installed = is_file(__DIR__ . '/.installed');

if (!$installed && !empty($_POST['user'])) {
    session_start();
    user_add($_POST['user'], $_POST['pass'], 'admin', $_POST['dir'], $_POST['ram'], $_POST['port']);
    file_put_contents(".installed", ""); // <------------- **Line 9**
    $_SESSION['user'] = clean_alphanum($_POST['user']);
}

/inc/lib.php相关代码:

// Write to file
file_put_contents('data/users/' . strtolower(clean_alphanum($user['user'])) . '.json', json_encode($user));

解决方法

这是典型的文件权限不足问题,PHP(Apache进程)没有权限写入data/users/目录和网站根目录来创建文件,按以下步骤修复:

  1. 确认Apache运行用户
    Ubuntu 18.04中Apache默认以www-data用户运行,执行命令验证:

    ps aux | grep apache2
    

    输出中第一列的用户即为Apache运行用户。

  2. 修复目录权限
    切换到网站根目录,给相关目录赋予www-data用户的读写权限:

    cd /var/www/html
    # 给data目录及子目录赋予www-data所有权
    sudo chown -R www-data:www-data data/
    # 设置目录权限为755(所有者读写执行,组和其他读执行)
    sudo chmod -R 755 data/
    # 给网站根目录赋予www-data写权限,以便创建.installed文件
    sudo chown www-data:www-data /var/www/html
    sudo chmod 755 /var/www/html
    
  3. 重新执行安装
    访问http://mywebsite.com/install.php,重新输入管理员信息完成安装,此时应该能正常生成data/users/jox.json和.installed文件。

  4. 可选:检查SELinux状态
    如果上述操作后仍报错,检查SELinux是否开启(Ubuntu默认未开启,部分定制环境可能开启):

    sudo sestatus
    

    若输出显示SELinux status: enabled,执行以下命令放宽Apache的文件访问限制:

    sudo setsebool -P httpd_unified 1
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 15:39:13