Drupal文件夹和文件权限

时间:2011-01-22 03:35:11

标签: drupal permissions

我有一段时间试图弄清楚我应该如何配置我的Drupal文件夹和文件。我已经在drupal.org上搜索了一下,但是一直想着运行需要访问“sites”和“files”文件夹的www-data,以及“settings.php”需要一些很棒的权限。

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

/ = 744或drwxr-r--
/ includes / = ...
/ misc / = ...
/ modules / = ...
/ profiles / = ...
/ scripts / = ...
/ sites / = ...
/ sites / all / = ...
/ sites / default / = ...
/sites/default/settings.php = 444?
/ sites / default / files / = ...

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

我真的很感激任何可以让我恢复理智的贡献! :)

斯科特

3 个答案:

答案 0 :(得分:5)

我本地计算机上的默认安装

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

drwxr-xr-x目录

drwxrwxr-x文件夹

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

答案 1 :(得分:3)

我的答复很晚,但我遇到了这个问题并找到了出路。 来自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

中提琴!您的权限会自动修复。

答案 2 :(得分:0)

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

B)为文件的所有者提供只读访问权限会导致复杂的维护过程(例如:大多数建议,Settings.php应该只读给所有人),这只会在您想要修改时增加任务设置。

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

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

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

网站文件夹

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

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

在这种情况下:kalpesh是文件所有者,守护程序是webservice所有者 - 它可能是您网站的www数据。

我通常将此脚本保存在.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