【问题标题】:Forbidden :You don't have permission to access /phpmyadmin on this server禁止:您无权访问此服务器上的 /phpmyadmin
【发布时间】:2014-06-07 18:12:39
【问题描述】:

您好,我在我的 centos 机器上安装了 phpmyadmin,当我尝试通过浏览器点击 phpmyadmin 时,我收到此错误:

Forbidden
You don't have permission to access `phpmyadmin` on this server.

我的phpmyadmin.conf 文件有以下内容:

# phpMyAdmin - Web based MySQL browser written in php
# 
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin


<Directory /usr/share/phpMyAdmin/>
   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       Require ip 127.0.0.1
       Require ip ::1
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 127.0.0.1
     Allow from ::1
   </IfModule>
</Directory>

<Directory /usr/share/phpMyAdmin/setup/>
   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       Require ip 127.0.0.1
       Require ip ::1
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 127.0.0.1
     Allow from ::1
   </IfModule>
</Directory>

# These directories do not require access over HTTP - taken from the original
# phpMyAdmin upstream tarball
#
<Directory /usr/share/phpMyAdmin/libraries/>
    Order Deny,Allow
    Deny from All
    Allow from None
</Directory>

<Directory /usr/share/phpMyAdmin/setup/lib/>
    Order Deny,Allow
    Deny from All
    Allow from None
</Directory>

<Directory /usr/share/phpMyAdmin/setup/frames/>
    Order Deny,Allow
    Deny from All
    Allow from None
</Directory>

# This configuration prevents mod_security at phpMyAdmin directories from
# filtering SQL etc.  This may break your mod_security implementation.
#
#<IfModule mod_security.c>
#    <Directory /usr/share/phpMyAdmin/>
#        SecRuleInheritance Off
#    </Directory>
#</IfModule>

请帮我解决这个问题。任何线索表示赞赏。

谢谢

【问题讨论】:

  • 但我说的是 Lamp 不是 wamp 仅供参考
  • 您目前只允许本地主机访问usr/share/phpmyadmin 我建议只添加 IP 白名单以确保安全。
  • 你的意思是用我的机器IP替换127.0.0.1。我也这样做了,但这个错误仍然存​​在。
  • 那个答案对我不起作用。任何帮助!

标签: php mysql phpmyadmin


【解决方案1】:

您需要遵循以下步骤:

查找下面的行

Require ip 127.0.0.1

替换为您的工作站 IP 地址:

Require ip 10.1.3.53

再次找到以下行:

Allow from 127.0.0.1

如下替换:

Allow from 10.1.3.53

同时找到deny from all 并在整个文件中进行注释。

保存并关闭文件。Restart Apache httpd server:

# service httpd restart

编辑:因为这是选定的答案并且获得最佳可见性...请同时确保已安装 PHP,否则您会收到相同的 Forbidden 错误。

【讨论】:

  • 我这样做并且工作正常,但我需要允许超过 1 个 IP 地址,我该怎么做?或者更好,我怎样才能允许公共访问?
  • 您可以像这样指定 IP 范围:Require ip 192.168 不要在 &lt;RequireAny&gt; 块中包含 Allow from。此处的文档:link
  • 这是正确答案。如果有人想知道,该文件位于此处 - /etc/httpd/conf.d/phpMyAdmin.conf
  • 感谢您发布实际的安全答案!
  • 既然你的答案是选定的,你能否在最后添加PHP 也应该安装?否则你会得到同样的Forbidden 错误,这是不直观的。
【解决方案2】:

首先编辑文件 /etc/httpd/conf.d/phpMyAdmin.conf 并将附加行添加到目录设置中:

<Directory /usr/share/phpMyAdmin/>
order deny,allow
deny from all
allow from 127.0.0.1
allow from 192.168.1.0/15
</Directory>

如果您想允许所有人访问,那么您可以将其更改为:

<Directory /usr/share/phpMyAdmin/>
order allow,deny
allow from all
</Directory>

允许文件的所有部分。

重新启动(服务 httpd 重新启动)就足以解决这个问题。

经过 2 天的严格研究,我发现了这个(找到它here)并且对我来说正好。

【讨论】:

  • 我尝试这样做但不工作,不允许所有访问 phpmyadmin,仍然有禁止页面
  • "allow from" 两行都改成"Required ip",删除两行命令然后deny就行了。
【解决方案3】:

允许所有人:

#Require ip 127.0.0.1
#Require ip ::1
Require all granted

【讨论】:

  • @DaemonOfTheWest,这是做什么的?
  • @gwg - 如果有人找出有效的用户/密码组合,他们可以访问你的数据库 - 这真的很糟糕 - 如果你忘记运行 /usr/bin/mysql_secure_installation 更是如此
  • 实际上,如果您的设置需要,请执行此操作。就像为需要通过 Internet 或您的 Intranet 访问它的多个用户安装 phpmyadmin 一样......并通过其他方式保护您的安装。看到人们告诉“永远不要这样做”,这令人震惊。他们似乎不知道 phpmyadmin 是为了什么而开发的。
【解决方案4】:

编辑文件:sudo nano /etc/httpd/conf.d/phpMyAdmin.conf 并用以下内容替换您的文件:

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8
   <IfModule mod_authz_core.c>
     # Apache 2.4
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
   </IfModule>
</Directory>

重启 Apache:service httpd restart

(phpMyAdmin v4.0.10.8)

【讨论】:

  • 试过你的解决方案得到:未找到在此服务器上找不到请求的 URL /phpMyAdmin。
  • 然后添加:别名/phpMyAdmin /usr/share/phpMyAdmin 别名/phpmyadmin /usr/share/phpMyAdmin.....现在得到:禁止您无权访问/phpMyAdmin服务器。
  • 对不起,它不适合你。这是一个2.5岁的答案。但要尝试调试,请确保 /usr/share/phpMyAdmin/ 存在或更改配置中的路径。
  • ls -lthr /usr/share/phpMyAdmin/ 总计 924K -rw-r--r-- 1 root root 1.2K 2017 年 3 月 29 日 webapp.php -rw-r--r-- 1根根 3.5K 2017 年 3 月 29 日 view_operations.php -rw-r--r-- 1 根根 7.0K 2017 年 3 月 29 日 view_create.php
【解决方案5】:

以上配置都不适用于我的 CentOS 7 服务器。经过数小时的搜索,这对我有用:

编辑文件 phpMyAdmin.conf

sudo nano /etc/httpd/conf.d/phpMyAdmin.conf

并将现有的&lt;Directory&gt; ... &lt;/Directory&gt; 节点替换为以下内容:

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       #Require ip 127.0.0.1
       #Require ip ::1
       Require all granted
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 127.0.0.1
     Allow from ::1
   </IfModule>
</Directory>

【讨论】:

  • 对于 Cent OS 7 来说是完美的
  • 这些新行有哪些(重要的)变化?
  • 这不是正确的答案!您不想Require all granted,因为这将允许任何主机访问 phpMyAdmin。 Require ip 127.0.0.1 的意图是只允许本地主机访问,这是安全的。
  • 我知道这种想法是不安全的,我也可以理解,但是在这种情况下正确的做法是什么?许多人使用不粘的动态IP。我会暂时将配置更改为此,然后将其更改回来,以便仅在必要时打开它,但这似乎不是最佳解决方案。
  • 答案还不清楚。在顶部替换这个......我们要替换什么?
【解决方案6】:

在 CENTOS7 上全新安装时,我尝试了上述方法(编辑 phpMyAdmin.conf 并添加 Require all grant),它仍然不起作用。这是解决方案:安装mod_php 模块:

$ sudo yum install php

然后重启httpd:

$ sudo systemctl restart httpd

瞧!

【讨论】:

  • 这个安装在 Ubuntu IMO 中处理得更好......但是,这就是生活。
  • 对我来说是正确的答案。我的机器上也没有安装 php 或 httpd。安装了phpmyadmin,然后是httpd,最后是php,现在可以正常使用了!
  • 不错的方向。必须首先确保已安装 php。
  • phpMyAdmin 的依赖项不包含 php 有点荒谬
  • 我安装了 mod_php:yum -y install mod_php 并重启了 apache。它奏效了。
【解决方案7】:

得票最多的答案的问题是它没有解释解决方案的原因。

对于Require ip 127.0.0.1 行,您应该添加计划从浏览器访问phpMyAdmin 的主机的IP 地址。例如Require ip 192.168.0.100Require ip 127.0.0.1 允许 localhost 访问 phpMyAdmin。

进行更改后重新启动 apache (httpd)。我建议在 localhost 上测试,或者使用 curl 之类的命令行工具来非常 http GET 工作,并且没有其他配置问题。

【讨论】:

    【解决方案8】:

    您可以简单地转到 phpmyadmin.conf 文件并将“全部拒绝”更改为“全部允许”。 好吧,它对我有用,希望它也对你有用。

    【讨论】:

      【解决方案9】:

      Centos 7 php install 附带安装和启用的 ModSecurity 包,它阻止了对 phpMyAdmin 的 Web 访问。在 phpMyAdmin.conf 的末尾,你应该找到

      # This configuration prevents mod_security at phpMyAdmin directories from
      # filtering SQL etc.  This may break your mod_security implementation.
      #
      #<IfModule mod_security.c>
      #    <Directory /usr/share/phpMyAdmin/>
      #        SecRuleInheritance Off
      #    </Directory>
      #</IfModule>
      

      它为您提供问题的答案。通过添加

          SecRuleEngine Off
      

      在“目录/usr/share/phpMyAdmin/”块中,您可以解决对phpmyadmin 的“拒绝访问”,但您可能会产生安全问题。

      【讨论】:

        【解决方案10】:

        Find your IP address 并将您看到的 127.0.0.1 替换为您从上面的链接获得的工作站 IP 地址。

        . . .
        Require ip your_workstation_IP_address
        . . .
        Allow from your_workstation_IP_address
        . . .
        Require ip your_workstation_IP_address
        . . .
        Allow from your_workstation_IP_address
        . . .
        

        最后别忘了重启服务器

        sudo systemctl restart httpd.service
        

        【讨论】:

          【解决方案11】:

          至少用最新版本的phpmyadmin 5.0.2+

          检查实际安装是否正确完成,

          我的已被复制到 linux 机器上的子文件夹中,而不是在

          /usr/share/phpmyadmin/
          

          【讨论】:

            【解决方案12】:

            在 appserver 中我遇到了同样的问题,我去了 'C:\AppServ\Apache24\conf\extra' 文件夹我修改了 httpd-vhosts.conf 文件

            <VirtualHost _default_:80>
            DocumentRoot "${SRVROOT}/htdocs"
            #ServerName www.example.com:80
            </VirtualHost>
            

            <VirtualHost _default_:80>
            DocumentRoot "C:\AppServ\www"
            #ServerName www.example.com:80
            </VirtualHost>
            

            【讨论】:

              【解决方案13】:

              For Centos OS (7.x), installed phpMyadmin -> "sudo yum install phpmyadmin"
              
              Edit file: "sudo nano /etc/httpd/conf.d/phpMyAdmin.conf"
              
              Alias /phpMyAdmin /usr/share/phpMyAdmin
              Alias /phpmyadmin /usr/share/phpMyAdmin
              
              <Directory /usr/share/phpMyAdmin/>
                 AddDefaultCharset UTF-8
                 <IfModule mod_authz_core.c>
                   # Apache 2.4
                   <RequireAny>
                     Require ip [...your_device_ip...]
                     Require ip ::1
                   </RequireAny>
                 </IfModule>
                 <IfModule !mod_authz_core.c>
                   # Apache 2.2
                   Order Deny,Allow
                   Deny from All
                   Allow from [...your_device_ip...]
                   Allow from ::1
                 </IfModule>
              </Directory>
              
              Change line:
              Require ip 118.2.141...
              Allow from 118.2.141...
              
              And restart the server:
              "Sudo service httpd restart"
              
              Database interface access link: http://your_device_ip/phpmyadmin/
              Good luck!

              【讨论】:

                猜你喜欢
                • 2017-08-10
                • 2012-01-12
                • 2021-06-15
                • 2012-05-22
                • 1970-01-01
                相关资源
                最近更新 更多