为两个组设置 /var/www

为两个组设置 /var/www

我有两个组。ftpgroup 和 www-data。我使用 proftpd 和 mysql 来存储 ftp 用户及其主目录。当用户注册时,它首先创建文件夹,然后在 MySQL 中创建用户帐户。我的问题在于,apache 似乎在创建目录时没有问题。然后用户可以登录,但之后他们没有写权限。主目录也是如此。当用户在 SQL 数据库中创建并限制在其主目录中时,他们会继承组 ftpgroup 和 ftpuser。我还看到我的主要用户无法在其主目录中写入。

/var/www 的权限:

drwxr-xr-x 4 www-data ftpgroup 4096 Jan 22 21:28 /var/www

当然可以chown -R ftpuser:ftpgroup /var/www,但 Apache 无法再写入/var/www/html/accounts

我尝试设置chown -R ftpuser:www-data /var/www,但仍然无法使用 apache 创建文件,设置为 时,chown -R www-data:ftpgroup我无法使用 ftp 修改任何文件。另一个值得关注的问题是,当 php 在查看权限后创建新目录时,apache 会引发什么样的权限问题。

当前创建文件夹的脚本

public function CreateUserFolder($arg,$arg2,$arg3) {
    if(file_exists(ROOT_PATH.'/accounts/'.$arg)) {
        echo "User Exists";

    }
    else {
    mkdir(ROOT_PATH.'/accounts/'.$arg, 0777, true);
    self::CreateFTPAccount($arg,$arg2,$arg3);
    }
}

答案1

我不确定这是否真的可以构成修复,但这就是我所做的,以便用户可以写入他们的目录。

chown -R ftpuser:ftpgroup /var/www

之后在/etc/apache2/envvars

# Since there is no sane way to get the parsed apache2 config in scripts, some
# settings are defined via environment variables and then used in apache2ctl,
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
export APACHE_RUN_USER=www-data //Replaced
export APACHE_RUN_GROUP=www-data //Replaced

并将其替换为

# Since there is no sane way to get the parsed apache2 config in scripts, some
# settings are defined via environment variables and then used in apache2ctl,
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
export APACHE_RUN_USER=ftpuser
export APACHE_RUN_GROUP=ftpgroup

到目前为止我没有发现任何问题,一切都运行良好。

相关内容