Xampp Access Forbidden php

时间:2013-07-23 17:12:49

标签: php xampp

我是一名Windows用户。我一直在使用xampp很长一段时间但突然间我的.php文件都没有正常工作! 我收到此错误消息:


禁止访问!

您无权访问请求的对象。它受读保护或服务器无法读取。

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

错误403

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


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

16 个答案:

答案 0 :(得分:101)

尝试使用以下代码,将其添加到虚拟主机配置中。将此行添加到httpd-vhosts.conf文件:

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

我通过这种方式解决了同样的问题。希望它有所帮助。

答案 1 :(得分:11)

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

打开终端按快捷键 Ctrl+Alt+T 转到

$ cd / opt / lampp / htdocs /

并使用chmod命令

更改文件夹读写和执行权限

例如文件夹名称是练习和文件夹的路径  的/ opt / LAMPP / htdocs中/实践

输入命令

$ sudo chmod 777 -R Practice

chmod777是什么?访问此链接 http://linuxcommand.org/lts0070.php

答案 2 :(得分:4)

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

<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:/ websites / test / logs /”后,请确保自己创建日志文件夹。错误日志中记录的确切错误是

  

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

我指出使用this link来解决上述错误的正确解决方案

Require all granted 

是必需的。我上面的示例示例代码解决了问题。

答案 3 :(得分:3)

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

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

答案 4 :(得分:2)

转到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

答案 5 :(得分:1)

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

答案 6 :(得分:1)

对我来说,以下问题立即得到解决

  1. 转到C:\ xampp \ apache \ conf \ extra
  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>

在此之后,本地主机将停止显示错误并显示管理面板。 我在以下视频中找到了此解决方案: https://www.youtube.com/watch?v=MvYyEPaNNhE

答案 7 :(得分:1)

对于Mac上的XAMPP

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

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

答案 8 :(得分:0)

我遇到了同样的问题。所以我得到了记忆。昨天我在htttp-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)上的其他系统访问我的本地主机,因为它使localhost需要本地。

所以我就这样做了

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

现在可以使用同一LAN / WIFI上的其他系统访问我的本地计算机以及localhost。

答案 9 :(得分:0)

您是否在虚拟主机停止工作之前更改了任何内容?

将此行添加到xampp / apache / conf / extra / httpd-vhosts.conf

vector<int> v;
int const *last = v.data() + v.size(); 

答案 10 :(得分:0)

在我的例子中,我将Drupal实例从服务器导出到XAMPP上的localhost。它显然没有公平对待文件和目录所有权,而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的用户是“守护进程”。您可以通过localhost:

在php文件中运行此php脚本来识别用户
<?php echo exec('whoami');?>

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

enter image description here

一旦将其运回服务器,您可能需要将其更改回来!

答案 11 :(得分:0)

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 **

答案 12 :(得分:0)

花了数小时进行在线研究后,唯一对我有用的解决方案

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

答案 13 :(得分:0)

我遇到了同样的错误,因为以某种方式删除了index.php并访问了该文件夹而没有 index.php给出了同样的错误。

答案 14 :(得分:0)

以下步骤可能会帮助任何人

  1. 检查apache2的错误日志
  2. 检查文件夹权限是否可访问 ?如果没有设置
  3. 在vhost文件中添加以下内容 <目录“ c://”> 选项索引FollowSymLinks多视图 允许全部覆盖 拒绝订单,允许 全部允许 要求所有授予
  4. 最后,但可以节省时间,例如您放入vhosts文件和实际名称的矿井检查文件夹名称(区分大小写的“ Pubic”与“ public”不同)。 谢谢

答案 15 :(得分:0)

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

AllowOverride none
Require all denied

AllowOverride All
Options  All
Allow from all
Order allow,deny

重启apache