Xampp:我无法从本地访问phpMyAdmin。

4
我正在尝试搭建Xampp进行家庭开发。它已经正确安装,我可以访问像演示、安全、状态等xampp页面...甚至使用phytin-gui启动和停止服务器。
但是,当我尝试使用“http://localhost/phpmyadmin”访问phpMyAdmin时,出现以下错误:
Access forbidden!

New XAMPP security concept:

Access to the requested directory is only available from the local network.

This setting can be configured in the file "httpd-xampp.conf".

我检查了我的httpd-xampp.conf文件,似乎是正确的。我尝试将拒绝所有更改为允许所有,但没有起作用。
我的主机文件将localhost指向127.0.0.1,这是访问所有xampp文件所期望的。
我在ubuntu 12.04机器上运行XAMPP 1.8.1。
有人遇到过同样的问题吗?我花了近两个小时在谷歌上搜索,但我发现当尝试从其他网络或机器访问服务器时会出现此错误。但对于我来说,情况是我直接在服务器上工作,所以默认情况下应该可以访问phpMyAdmin。
我的httpd-xampp.conf文件。
#
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
    Order deny,allow
    Deny from all
    Allow from ::1 127.0.0.0/8 \
        fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 \
        fe80::/10 169.254.0.0/16

    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>

看一下我在这个主题中的回答:https://dev59.com/9Wct5IYBdhLWcg3wKqMd#16617319 - Andy
4个回答

6

如果您将XAMPP安装在/opt目录下,请前往/opt/lampp/etc/extra目录,并编辑httpd-xampp.conf文件,按以下方式添加Require all granted

# since XAMPP 1.4.3
<Directory "/opt/lampp/phpmyadmin">
    AllowOverride AuthConfig Limit
    Order allow,deny
    Allow from all
    Require all granted
</Directory>

你可能需要通过运行/opt/lampp/lampp restart来重新启动你的LAMPP服务器。

1
这不就是一种禁用phpmyadmin路径下所有安全性的黑客技巧吗?那么错误的真正原因是什么?参考:Require DirectiveRequire all granted Access is allowed unconditionally. - user166560
您指出上面的解决方案授予了无条件访问权限,是正确的。原因:127.0.0.1只能访问安全文件夹,并拒绝来自局域网的访问。为了解决这个问题并在一定程度上保持安全性,您可以尝试下面的代码:<br/>Allow from xxx.xxx.x.xxx xxx.xxx.x.xxx如果您想要添加多个IP地址到Allow from规则中,只需在最后一个IP地址后面加上一个空格,或者以反斜杠“\”结束一行,然后您可以直接在下一行编写。 - 000

2

我在XAMPP自己的论坛中也发现了这个问题。虽然提到了Require all granted的答案,但是这样会无条件地授予访问权限。该帖子继续提供更好的解决方案

Just update your httpd-xampp.conf. Replace the End with:

#
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
    <RequireAny>
        Require ip ::1 127.0.0.0/8 \
        fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 \
        fe80::/10 169.254.0.0/16
    </RequireAny>
    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>

Then restart your lampp with: sudo /opt/lampp/lampp restart

参考:http://httpd.apache.org/docs/2.4/mod/mod_authz_core.html#require

这是一个关于Apache Web服务器模块mod_authz_core的文档。其中讨论了一种名为Require的指令,可用于设置对资源的访问控制。使用Require可以定义允许或禁止访问资源的条件,如用户身份验证状态、IP地址和HTTP请求标头。您可以根据需要将多个Require指令组合在一起,以创建更复杂的访问控制规则。

0
我通过为phpmyadmin创建一个新的虚拟主机来解决了这个问题。
请将以下内容添加到C:/xampp/apache/conf/httpd.conf中:
NameVirtualHost phpmyadmin.local

<VirtualHost phpmyadmin.local>
  ServerName phpmyadmin.local
  DocumentRoot "C:/xampp/htdocs/phpmyadmin"
  <Directory "C:/xampp/htdocs/phpmyadmin">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

DocumentRoot/Directory 更改为您安装 phpmyadmin 版本的路径。

在文本编辑器中打开 C:\Windows\System32\drivers\etc\hosts 文件,并添加以下行:

127.0.0.1     phpmyadmin.local

然后保存hosts文件并重新启动xampp

https://dev59.com/9Wct5IYBdhLWcg3wKqMd#16617319


0

这个答案适用于XAMPP 1.8.2 [PHP:5.4.25]

只需在Require local下面加上#号,重要的是,在xampp控制面板中停止和启动Apache。就这样,它一定会起作用。

<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
       #Require local

    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接