Answers:
其实权限应该是
sites -> 755
sites/default -> 755
sites/default/files -> 775
sites/default/settings.php -> 444
有关一些详细信息,请参见此问题的前3个答案。
将其复制到文件中,并将其命名为“ 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 =您的/ drupal / path --drupal_user =您的用户名
中提琴!您的权限将自动修复。
这就是我决定为我的Drupal实例设置权限的方式:
mkdir sites/default/files
chgrp -Rv apache sites/default/files
chmod 2775 sites/default/files
我们通过在chmod命令中使用2775来完成此操作。2表示将为在此目录中创建的任何新文件保留组ID。这意味着apache将始终是任何文件上的组,从而确保Web服务器和用户都将始终具有对该目录中放置的任何新文件的写权限。前7个表示所有者(示例)可以R(读)W(写)和X(执行)此处的任何文件。第二个7表示组(www-data)也可以读写该目录中的任何文件。最后,5表示其他用户可以R和X文件,但不能写入。
另一点是为您的settings.php设置正确的权限
chmod 444 sites/default/settings.php
其他权限是默认的。
完整的Drupal安装指南:http : //itvictories.com/node/21
选择的答案不是很正确,特别是在那里未知的地方时,但是Aleks对此进行了广泛的解释,这与我在Drupal网站上采取的方法非常相似。
另外,我想我也会在这里分享我的脚本,但是作为我之前创建的Drupal模块。您可以将其放在~/.drush
子目录中,然后drush file-permissions
在任何可用的Drupal站点子目录中执行即可。
它引导您的Drupal站点,检查file_private_path
,file_public_path
然后将其设置为正确的Apache用户和组。Apache用户/组是自动确定的,因此它不依赖于用户手动指定它们或在脚本文件中对其进行硬编码。