禁止访问

我是 Windows 用户。我使用 xampp 已经有一段时间了,但是突然之间。Php 文件正在工作! 我得到这个错误消息:


禁止进入!

您没有访问所请求对象的权限。该对象要么是受读保护的,要么是服务器无法读取的。

如果您认为这是一个服务器错误,请与网站管理员联系。

错误403

本地主机 Apache/2.4.4(Win32) OpenSSL/0.9.8 y PHP/5.4.16


我可以在 localhost/Practice 中看到我的. php 文件列表(Practice 是我保存文件的文件夹) 这个文件甚至在我点击它的时候就会打开。 但是当我点击任何文件中的“提交”按钮时,就会出现这个错误。 请帮助! 我将 xampp 从1.8.1更新到1.8.2,但是仍然存在同样的问题!

350833 次浏览

进入 Xampp 文件夹 xampp/apache/conf/extra/httpd-xampp.c­onf

编辑最后一段:

#close XAMPP sites here
.
.
.
Deny from all
.
.

#close XAMPP sites here
.
.
.
Allow from all
.
.

或者看看这个视频: http://www.youtube.com/watch?v=ZUAKLUZa-AU

尝试使用下面的代码,将其添加到您的虚拟主机配置中:

<Directory "c:/<path-to-projects>/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>

我用这种方法解决了同样的问题。希望对你有帮助。

注:

因为您通过缓存进行了重定向

如果使用 ubuntu 操作系统,那么检查 chmod/Practice 文件夹 更改读写权限

打开终端按快捷键 Ctrl+Alt+T 后藤

$cd/opt/lampp/htdocs/

并使用 chmod命令更改文件夹的读写和执行权限

G 文件夹名称是实践和文件夹的路径 /opt/lampp/htdocs/Practice

输入命令

$ sudo chmod 777 -R Practice

什么是 chmod777 Http://linuxcommand.org/lts0070.php

我在将 htdocs 文件夹移到 xampp 文件夹之外时遇到了这个问题。如果这样做,那么需要更改 httpd.conf 中的文档根目录。参见 https://stackoverflow.com/a/1414/3543329

我也遇到了同样的问题,所以我想起来了,昨天我在 http-xampp.conf 中注释了这段代码

Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
#        AllowOverride AuthConfig
#        Require local
#        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>

因此,我可以使用同一网络上的其他系统(LAN/WIFI)访问我的本地主机,因为它使本地主机需要本地。

所以我就让它看起来

Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
AllowOverride AuthConfig
#        Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>

现在它可以在我的本地机器上工作,也可以在同一个 LAN/WIFI 上使用其他系统访问本地主机。

在虚拟主机停止工作之前,你对它做了什么修改吗?

将这一行添加到 xampp/apache/conf/tra/httpd-vhosts. conf

<VirtualHost localhost:80>
DocumentRoot "C:/xampp/htdocs"
ServerAdmin localhost
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

在我的例子中,我在 XAMPP 上将 Drupal 实例从服务器导出到本地主机。它显然没有公正地处理文件和目录所有权,Apache 抛出了上述错误。

这是最初文件和目录的所有权:

enter image description here

为了给我的文件提供读取权限,并对我的目录提供执行权限,我可以这样做,所有用户都可以读、写和执行:

sudo chmod 777 -R

但这不是理想的解决方案,因为这将被迁移回服务器,最终可能出现安全漏洞。

这个博客给出了一个脚本: https://www.drupal.org/node/244924

#!/bin/bash


# 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
}


if [ $(id -u) != 0 ]; then
printf "**************************************\n"
printf "* Error: You must run this with sudo or root*\n"
printf "**************************************\n"
print_help
exit 1
fi


drupal_path=${1%/}
drupal_user=${2}
httpd_group="${3:-www-data}"


# 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 "***********************************************************\n"
printf "* Error: Invalid argument, run --help for valid arguments. *\n"
printf "***********************************************************\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 "*********************************************\n"
printf "* Error: Please provide a valid Drupal path. *\n"
printf "*********************************************\n"
print_help
exit 1
fi


if [ -z "${drupal_user}" ] || [[ $(id -un "${drupal_user}" 2> /dev/null) != "${drupal_user}" ]]; then
printf "*************************************\n"
printf "* Error: Please provide a valid user. *\n"
printf "*************************************\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 setting proper permissions on files and directories"

并且需要调用命令:

sudo bash /Applications/XAMPP/xamppfiles/htdocs/fix-permissions.sh --drupal_path=/Applications/XAMPP/xamppfiles/htdocs/rkmission --drupal_user=daemon --httpd_group=admin

在我的例子中,运行 Apache 的用户是‘ daemon’。您可以通过 localhost 在 php 文件中运行这个 php 脚本来识别用户:

<?php echo exec('whoami');?>

下面是对 Drupal 具有正确文件权限的正确用户:

enter image description here

一旦它被传输回服务器,您可能必须将其更改回来!

A. #LoadModule vhost_alias_module modules/mod_vhost_alias.so
B. <Directory />
AllowOverride none
Require all denied
</Directory>

替换为:

A. LoadModule vhost_alias_module modules/mod_vhost_alias.so
B:
<Directory />
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

E: xamp * * apache conf/httpd.conf * *

我解决这个问题的方法首先是正确地设置错误日志

<VirtualHost *:80>
DocumentRoot "D:/websites/test/"
ServerName test.dev
ErrorLog "D:/websites/test/logs/error.log"
CustomLog "D:/websites/test/logs/access.log" common
<Directory D:/websites/test/>
AllowOverride none
Require all granted
</Directory>
</VirtualHost>

在这个错误被记录到“ D:/sites/test/log/”确保自己创建日志文件夹之后,错误日志中记录的确切错误是

AH01630: 客户端被服务器配置拒绝:

这指出了我正确的解决方案使用 这个链接说,对于上述错误

Require all granted

上面的示例代码顺便修复了这个问题。

我正在使用 ubuntu 16.04使用 xxamp-它对我来说工作得很好

<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/"
ServerAdmin localhost
<Directory "/opt/lampp/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

对我来说,这个问题很快就解决了

  1. 转到 C: xampp apache conf plus
  2. 在 httpd-xampp. conf 文件内进行编辑
  3. 编辑文件如下:

通过 cont + f 查找以下行:

Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
AllowOverride AuthConfig
Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>

只改变本地—— > 全部同意,所以它变成这样

Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
AllowOverride AuthConfig
Require all granted
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>

在此之后,localhost 将停止显示错误并显示管理面板。 我在一段视频中找到了这个解决方案: Https://www.youtube.com/watch?v=mvyyepannhe

我花了好几个小时在网上搜索,唯一有效的解决办法

sudo chmod -R 0777 /opt/lampp/htdocs/projectname

用于 Mac 上的 XAMPP

sudo chmod -R 0777 /Applications/XAMPP/xamppfiles/htdocs/myprojectname

注意: 请记住将“ myprojectname”更改为您的实际项目名称。另外,确保该项目位于 htdocs 的根目录中,或者相应地更改路径。

我得到了同样的错误,因为不知怎么删除了 index.php 并访问了文件夹 Php 也出现了同样的错误。

下面的步骤可能对任何人都有帮助

  1. 检查 apache2的错误日志
  2. 检查文件夹权限是否可访问 ♪ If not set it ♪
  3. 在 vhost 文件中添加以下内容 < 目录“ c://”> 选项索引遵循 SymLinks MultiView 允许覆盖所有 命令拒绝,允许 允许所有人 要求全部批准
  4. 最后,但可能节省时间像我的检查文件夹名称(大小写敏感的“公共”是不同的形式“公共”) ,你放在 vhosts 文件和实际名称。 谢谢

编辑此文件 C:\xampp\apache\conf\httpd.conf 改变:

AllowOverride none
Require all denied

AllowOverride All
Options  All
Allow from all
Order allow,deny

重启阿帕奇

方法-1

  • 这是针对 htdocs文件夹中的特定项目/文件夹
  1. 打开您的 终端机并转到 htdocs文件夹目录对我来说是(/opt/lampp/htdocs/) ,我使用(Cd 目录 _ name)命令来更改目录

    cd /opt/lampp/htdocs/

  2. 然后运行以下命令

    sudo chmod 777 -R Project-Folder-Name

用你的 项目文件夹名称代替 项目-文件夹-名称

路 -2

  • 这适用于 lampp文件夹中的所有项目/文件夹
  1. 打开您的 终端机并转到 lampp文件夹目录对我来说是(/opt/lampp/) ,我使用(Cd 目录 _ name)命令来更改目录

    cd /opt/lampp/

  2. 然后运行以下命令

    sudo chmod 777 -R htdocs