新的xampp安全概念:访问被拒绝错误403 - Windows 7 - phpMyAdmin

67

我已经在Windows 7 Ultimate上下载并安装了XAMPP 1.8.1 for Windows,按照这些说明设置了XAMPP与IIS一起运行。

到目前为止都很好,我的PHP网站在本地运行,除了phpMyAdmin之外的所有内容都可以从XAMPP菜单中访问。

然而,当我尝试访问phpMyAdmin时,我收到以下错误:

禁止访问!

新的XAMPP安全概念:

所请求目录的访问仅限于本地网络。

此设置可以在文件“httpd-xampp.conf”中进行配置。

我通过谷歌找到了几个答案,并在这个网站上找到了一些。然而,到目前为止,我尝试过的解决方案都没有解决这个问题。

这是我的httpd-xampp.conf文件:

#
# XAMPP settings
#

<IfModule env_module>
    SetEnv MIBDIRS "C:/xampp/php/extras/mibs"
    SetEnv MYSQL_HOME "\\xampp\\mysql\\bin"
    SetEnv OPENSSL_CONF "C:/xampp/apache/bin/openssl.cnf"
    SetEnv PHP_PEAR_SYSCONF_DIR "\\xampp\\php"
    SetEnv PHPRC "\\xampp\\php"
    SetEnv TMP "\\xampp\\tmp"
</IfModule>

#
# PHP-Module setup
#
LoadFile "C:/xampp/php/php5ts.dll"
LoadModule php5_module "C:/xampp/php/php5apache2_4.dll"

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

#
# PHP-CGI setup
#
#<FilesMatch "\.php$">
#    SetHandler application/x-httpd-php-cgi
#</FilesMatch>
#<IfModule actions_module>
#    Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
#</IfModule>


<IfModule php5_module>
    PHPINIDir "C:/xampp/php"
</IfModule>

<IfModule mime_module>
    AddType text/html .php .phps
</IfModule>

ScriptAlias /php-cgi/ "C:/xampp/php/"
<Directory "C:/xampp/php">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
          Require all granted
    </Files>
</Directory>

<Directory "C:/xampp/cgi-bin">
    <FilesMatch "\.php$">
        SetHandler cgi-script
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler None
    </FilesMatch>
</Directory>

<Directory "C:/xampp/htdocs/xampp">
    <IfModule php5_module>
        <Files "status.php">
            php_admin_flag safe_mode off
        </Files>
    </IfModule>
    AllowOverride AuthConfig
</Directory>

<IfModule alias_module>
    Alias /security "C:/xampp/security/htdocs/"
    <Directory "C:/xampp/security/htdocs">
        <IfModule php5_module>
            <Files "xamppsecurity.php">
                php_admin_flag safe_mode off
            </Files>
        </IfModule>
        AllowOverride AuthConfig
        Require all granted
   </Directory>

    Alias /licenses "C:/xampp/licenses/"
    <Directory "C:/xampp/licenses">
        Options +Indexes
        <IfModule autoindex_color_module>
            DirectoryIndexTextColor  "#000000"
            DirectoryIndexBGColor "#f8e8a0"
            DirectoryIndexLinkColor "#bb3902"
            DirectoryIndexVLinkColor "#bb3902"
            DirectoryIndexALinkColor "#bb3902"
        </IfModule>
        Require all granted
   </Directory>

    Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
    <Directory "C:/xampp/phpMyAdmin">
        AllowOverride AuthConfig Limit
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>

    Alias /webalizer "C:/xampp/webalizer/"
    <Directory "C:/xampp/webalizer">
        <IfModule php5_module>
            <Files "webalizer.php">
                php_admin_flag safe_mode off
            </Files>
        </IfModule>
        AllowOverride AuthConfig
        Require all granted
    </Directory>
</IfModule>

#
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
    Order deny,allow
    Allow from all
    Require all granted

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

有人知道我缺少什么吗?


如果有人需要帮助:在尝试下面回答中的任何好建议之前,请仔细检查您的目录中是否有一个索引文件,该文件指向... - Wtower
21个回答

107

您需要做的就是编辑httpd-xampp.conf文件

将LocationMatch标签中的Require local改为Require all granted

就这样!


这对我来说是有效的(在封闭系统上),但对其他人的安全影响我一点都不清楚 :-/ - jcansell
2
您可能还需要注释掉:Deny from all,并在LocationMatch标签下添加:Allow from all - shasi kanth
5
找不到这样的标签,LocationMatch标签。 - AVI
1
这在当前的XAMPP版本中不起作用,相反,当您添加虚拟主机时,只需添加Require all granted即可。以下是我的示例,您不需要全部内容。httpd-ssl.conf <VirtualHost *:443> DocumentRoot "full-path" ServerName ie.test1 ServerAlias ie.test1 ServerAdmin a@d.com SSLEngine On SSLCertificateFile "full-path.cert" SSLCertificateKeyFile "full-path.key" ErrorLog "full-path/error.log" TransferLog "full-path/access.log" Options All Require all granted </VirtualHost> - isaacewing
httpd-xampp.conf 文件位于 /opt/lampp/etc/extra/httpd-xampp.conf Linux。 - Elisha Senoo
显示剩余3条评论

36

在新版的Xampp中

你所要做的就是编辑文件:

C:\xampp\apache\conf\extra\httpd-xampp.conf

并前往以下的Directory标签:

<Directory "C:/xampp/phpMyAdmin">

然后更改

Require local

Require all granted

在Directory标签中。

重新启动Xampp,就这样!


1
谢谢@TheMohanAhuja,它有效。如果您想允许本地网络中特定IP地址的PC,请在同一\httpd-xampp.conf文件中在“Require local”下方添加“Require ip X.X.X.X”行。 - Deepak Goswami
这对我很有帮助。在更改后,只需在控制面板中停止/启动Apache。 - FAB
4
你好,我遇到了同样的问题,我的修改是将 "Require all granted" 添加进去,但是出现了“访问被禁止”的错误,有什么修改方法吗?请帮我解决。 - seema
@Seema 你重启了xampp吗? - TheMohanAhuja
@TheMohanAhuja 是的先生,我已经重新启动了XAMPP,但它仍然无法正常工作。 - seema
@Seema,您可以分享一下您的配置文件是什么样的,以便我们更好地了解您的问题吗? - TheMohanAhuja

18

看起来 Require all granted 对我来说有点过了。根据文档,我使用了 Require ip 192.168 来允许所有内部访问。

<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
    Require local
    Require ip 192.168
    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>

16

XAMPP 7.3.*更新

如果你像我一样在最新版的XAMPP中遇到了phpmyadmin的同样问题,解决方法可以在官方文档中找到。文档位于[XAMPP IP]/dashboard/docs/access-phpmyadmin-remotely.html

按照以下步骤启用来自其他主机的对phpMyAdmin的远程访问:

  1. 通过双击挂载的磁盘映像中的XAMPP图标启动堆栈管理器。
  1. 确保Apache和MySQL服务在堆栈管理器的“服务”选项卡中正在运行(或根据需要启动它们)。
  1. 从堆栈管理器的“通用”选项卡中打开一个新的终端。
  1. 编辑/opt/lampp/etc/extra/httpd-xampp.conf文件。
  1. 在该文件中查找块<Directory "/opt/lampp/phpmyadmin">

更新此块并将Require local替换为Require all granted,

  1. 保存文件并使用堆栈管理器重新启动Apache服务。

第4部分说明:确保安装了vim,然后才能编辑此文件。

第5部分的说明:如果您的计算机连接到网络,则不要允许所有人都有访问权限(这样非常不安全)。一个更安全的方法是将访问限制为一组IP地址,就像@Gunnar Bernstein建议的那样。

在我的情况下,我做了如下操作:

<Directory "/opt/lampp/phpmyadmin">
  AllowOverride AuthConfig Limit
  Require local
  Require ip 192.168
  ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>

2
这个解决方案太棒了!在找到它之前浪费了好几个小时 :D 谢谢。 - Harun Yilmaz

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

        Require all granted
    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>

祝你好运!!!!


10

尝试重新安装新版本的XAMPP。找到“<Directory "C:/xampp/php">”,然后更改为类似以下内容

<Directory "C:/xampp/php">
    AllowOverride AuthConfig Limit
    Order allow,deny
    Allow from all
    Require all granted
</Directory>

9

您需要编辑两个文件 - 1. httpd-vhosts.conf 和 2. httpd-xampp.conf

注意:确保备份文件(httpd-xampp.conf)和(httpd-vhosts.conf),这两个文件位于Drive:\xampp\apache\conf\extra中

打开httpd-vhosts.conf文件,在文件底部进行更改

<VirtualHost *:80>
DocumentRoot “E:/xampp/htdocs/”
ServerName localhost
<Directory E:/xampp/htdocs/>.
Require all granted 
</Directory>
</VirtualHost>

这里的 E:/xampp 是我的项目工作区,您可以根据自己的设置更改它。

第二个更改是在 httpd-xampp.conf 文件中,在文件底部进行更改。

#
# New XAMPP security concept
#
<LocationMatch “^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))”>
Order deny,allow
Allow from all
Allow from ::1 127.0.0.0/8
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>

4
访问除了本地网络以外的目录,需要更改在文件“httpd-xampp.conf”中配置的XAMPP安全概念

  • 文件位置xampp\apache\conf\extra\httpd-xampp.conf

Require指令选择哪些经过身份验证的用户可以访问资源

语法 « Require实体名称[实体名称] …

从“XAMPP安全概念仅允许本地环境 - Require local”开始。

<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
        Require local
    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>

XAMPP的安全概念允许任何环境——要求所有授权

<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
        Require all granted
    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>

访问被禁止!来自HTML页面的消息。

enter image description here


Allow指令控制哪些主机可以访问服务器区域。

语法 « Allow from all|host|env=[!]env-variable [host|env=[!]env-variable] ...

仅允许本地环境。使用下面任何一个指定的URL。

  • http://localhost/phpmyadmin/
  • http://127.0.0.1/phpmyadmin/

    <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 \
    
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
    </LocationMatch>
    

仅允许指定的IPv4IPv6地址空间。

  • Link-local addresses for IPv4 are defined in the address block 169.254.0.0/16 in CIDR notation. In IPv6, they are assigned the address block fe80::/10
  • A unique local address (ULA) is an IPv6 address in the block fc00::/7

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

允许任何网络地址. 允许全部

<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
    Order deny,allow
    Allow from all

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

404 - XAMPP 控制面板:无法启动 Apache HTTP 服务器

URL: http://localhost/xampp/index.php

Error « 
    Not Found
    HTTP Error 404. The requested resource is not found.

所需的默认Apache HTTP服务器端口80实际上被其他服务使用了。

  • You need to find the service running with port 80 and stop the service, then start the Apache HTTP server.

    Use Netstat to displays active TCP connections, ports on which the computer is listening.

     C:\Users\yashwanth.m>netstat -ano
    
      Active Connections
    
      Proto  Local Address          Foreign Address        State           PID
      TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       2920
      TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       1124
    
      TCP    127.0.0.1:5354         0.0.0.0:0              LISTENING       3340
    
      TCP    [::]:80                [::]:0                 LISTENING       2920
    
    C:\Users\yashwanth.m>netstat -ano |findstr 2920
      TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       2920
      TCP    0.0.0.0:443            0.0.0.0:0              LISTENING       2920
      TCP    [::]:80                [::]:0                 LISTENING       2920
      TCP    [::]:443               [::]:0                 LISTENING       2920
    
    C:\Users\yashwanth.m>taskkill /pid 2920 /F
      SUCCESS: The process with PID 2920 has been terminated.
    
  • Change listening port from main Apache HTTP server configuration file D:\xampp\apache\conf\httpd.conf. Ex: 81. From Listen 80 To Listen 81, the access URL will be http://localhost:81/xampp/index.php.

    # Change this to Listen on specific IP addresses as shown below to 
    # prevent Apache from glomming onto all bound IP addresses.
    #
    #Listen 0.0.0.0:80
    #Listen [::]:80
    Listen 80
    

想要了解更多关于在XAMPP上使用httpd和虚拟主机的信息,请参考httpd和虚拟主机在XAMPP上的使用


你很厉害,Yash :) - Vladimir

3

将 httpd-xampp.conf 文件中的 Require local 这一行注释掉。
重启 Apache。
我通过这种方式成功将我的手机连接到了我的测试网站上。
不清楚对安全性有何影响。


2

只需删除:

Alias /phpmyadmin "C:/xampp2/phpMyAdmin/"
<Directory "C:/xampp2/phpMyAdmin">
    AllowOverride AuthConfig
    Require all granted
</Directory>

并从中删除phpmyadmin:

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

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