【问题标题】:Drupal Folder and File PermissionsDrupal 文件夹和文件权限
【发布时间】:2011-06-13 13:17:13
【问题描述】:

我正忙着弄清楚应该如何配置我的 Drupal 文件夹和文件。我已经在 drupal.org 上进行了搜索,但不断提出有关 www-data 需要访问“站点”和“文件”文件夹以及“settings.php”如何需要一些很棒的权限的运球。

但我需要的是这样的列表:

/ = 744 或 drwxr-r--
/包括/ = ...
/misc/ = ...
/模块/ = ...
/profiles/ = ...
/scripts/ = ...
/sites/ = ...
/sites/all/ = ...
/sites/default/ = ...
/sites/default/settings.php = 444?
/sites/default/files/ = ...

我认为我不需要有人为我编目每个文件、文件夹和权限设置。我猜我可以将根文件夹权限设置为“应用于封闭项目”,然后修复需要特殊设置的几个文件夹和文件。

我非常感谢任何能让我恢复理智的贡献! :)

斯科特

【问题讨论】:

  • 最好在谷歌上搜索有关 Drupal 的答案,因为现在和那时,您最终会访问 Stackoverflow。问答各+1。

标签: drupal permissions


【解决方案1】:

我的本​​地机器上默认安装有

-rw-r--r--所有php文件

drwxr-xr-x 目录

drwxrwxr-x 文件夹

-r--r--r-- settings.php文件

【讨论】:

  • 感谢您抽出宝贵时间查看您的设置并进行报告。这些对我有用。
【解决方案2】:

我很晚才回复,但我遇到了这个问题并找到了解决办法。 来自Drupal's official handbook

将其复制到一个文件中并将其命名为“fix-permissions.sh”

#!/bin/bash
if [ $(id -u) != 0 ]; then
        printf "This script must be run as root.\n"
        exit 1
fi
drupal_path=${1%/}
drupal_user=${2}
httpd_group="${3:-www-data}"
# Help menu
print_help() {
cat <<-HELP
This script is used to fix permissions of a Drupal installation
you need to provide the following arguments:
1) Path to your Drupal installation.
2) Username of the user that you want to give files/directories ownership.
3) HTTPD group name (defaults to www-data for Apache).
Usage: (sudo) bash ${0##*/} --drupal_path=PATH --drupal_user=USER --httpd_group=GROUP
Example: (sudo) bash ${0##*/} --drupal_path=/usr/local/apache2/htdocs --drupal_user=john --httpd_group=www-data
HELP
exit 0
}
# Parse Command Line Arguments
while [ $# -gt 0 ]; do
        case "$1" in
                --drupal_path=*)
drupal_path="${1#*=}"
;;
--drupal_user=*)
drupal_user="${1#*=}"
;;
--httpd_group=*)
httpd_group="${1#*=}"
;;
--help) print_help;;
*)
printf "Invalid argument, run --help for valid arguments.\n";
exit 1
esac
shift
done
if [ -z "${drupal_path}" ] || [ ! -d "${drupal_path}/sites" ] || [ ! -f "${drupal_path}/core/modules/system/system.module" ] && [ ! -f "${drupal_path}/modules/system/system.module" ]; then
printf "Please provide a valid Drupal path.\n"
print_help
exit 1
fi
if [ -z "${drupal_user}" ] || [ $(id -un ${drupal_user} 2> /dev/null) != "${drupal_user}" ]; then
printf "Please provide a valid user.\n"
print_help
exit 1
fi
cd $drupal_path
printf "Changing ownership of all contents of "${drupal_path}":\n user => "${drupal_user}" \t group => "${httpd_group}"\n"
chown -R ${drupal_user}:${httpd_group} .
printf "Changing permissions of all directories inside "${drupal_path}" to "rwxr-x---"...\n"
find . -type d -exec chmod u=rwx,g=rx,o= '{}' \;
printf "Changing permissions of all files inside "${drupal_path}" to "rw-r-----"...\n"
find . -type f -exec chmod u=rw,g=r,o= '{}' \;
printf "Changing permissions of "files" directories in "${drupal_path}/sites" to "rwxrwx---"...\n"
cd sites
find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
printf "Changing permissions of all files inside all "files" directories in "${drupal_path}/sites" to "rw-rw----"...\n"
printf "Changing permissions of all directories inside all "files" directories in "${drupal_path}/sites" to "rwxrwx---"...\n"
for x in ./*/files; do
find ${x} -type d -exec chmod ug=rwx,o= '{}' \;
find ${x} -type f -exec chmod ug=rw,o= '{}' \;
done
echo "Done settings proper permissions on files and directories"

现在运行这个脚本:

 sudo bash fix-permissions.sh --drupal_path=your/drupal/path --drupal_user=your_user_name

维奥拉!您的权限会自动修复。

【讨论】:

  • 非常感谢。有用的链接和很棒的脚本。
【解决方案3】:

A) 不建议以任何形式访问世界,即使它只是读取访问权限。

B) 只给文件的所有者一个读取权限会导致复杂的维护过程(例如:最推荐,Settings.php 应该对所有人都是只读的),这只会增加你想要修改的任务设置。

简而言之: - 世界需要 0 访问 - 甚至不需要公共文件夹。 - 您的 Web 服务器需要对所有文件进行只读访问,除了 public 文件夹和 tmp 文件夹 - 这些文件都是可读写的。 - 您的文件所有者需要完全访问所有文件 - 以保持维护简单

但是,当文件所有者和网络服务器所有者是 2 个不同的用户并且您对服务器具有 ssh 控制权并且能够修改文件所有权时,这将最有效。

当您具有以下目录结构时,以下脚本将起作用:

网站文件夹

站点文件夹/conf(包含该站点的 apache 虚拟主机配置文件)

站点文件夹/htdocs(包含站点)

在这种情况下:kalpesh 是文件所有者,daemon 是 Web 服务所有者 - 它可能是您网站的 www-data。

我通常将此类脚本保存在 .sh 文件中,然后将其添加到 cron,这样每当我的团队成员在站点上上传新内容或更新模块时,站点权限就不会因他们的错误而受到损害。 Cron 将每 24 小时执行一次脚本并修复权限。

cd ToSiteFolder

sudo chown kalpesh:daemon .

sudo chmod 750 .

sudo chown -R kalpesh_popat:daemon ./conf

sudo find ./conf -type d -exec chmod 750 {} +
sudo find ./conf -type f -exec chmod 640 {} +

sudo chown -R kalpesh_popat:daemon ./htdocs

sudo find ./htdocs -type d -exec chmod 750 {} +
sudo find ./htdocs -type f -exec chmod 640 {} +

sudo find ./htdocs/sites/default/files -type d -exec chmod 770 {} +
sudo find ./htdocs/sites/default/files -type f -exec chmod 660 {} +

sudo find ./htdocs/tmp -type d -exec chmod 770 {} +

sudo chmod 640 ./htdocs/sites/default/settings.php

sudo chmod 750 ./htdocs/sites/default

有一个博客很好地解释了这一点并打破了许多神话。 https://technologymythbuster.blogspot.com/2018/06/misconception-about-file-ownerships-and.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-06
    • 2020-08-08
    • 2013-12-22
    • 2011-08-12
    • 2020-10-30
    • 2012-11-21
    相关资源
    最近更新 更多