【问题标题】:phpMyAdmin allow remote usersphpMyAdmin 允许远程用户
【发布时间】:2014-07-05 11:04:05
【问题描述】:

我需要修改文件/etc/httpd/conf.d/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>

【问题讨论】:

  • 你希望它对所有人开放还是只对特定的 IP 地址开放?
  • 我要给大家打开
  • 你有没有让这个工作?
  • @Euloiix 否,因为运行 PHPmyAdmin 的虚拟机不再可用

标签: php mysql phpmyadmin mariadb


【解决方案1】:

替换第一个&lt;directory&gt;标签的内容。

删除:

<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/>
 Order allow,deny
 Allow from all
</Directory>

之后别忘了重启 Apache。

【讨论】:

  • mag 16 23:33:29 localhost.localdomain httpd[2212]:httpd:/etc/httpd/conf/httpd.conf 第 353 行的语法错误:/etc 第 11 行的语法错误/httpd/conf.d/phpMyAdmin.conf: /etc/httpd mag 16 23:33:29 localhost.localdomain systemd[1]: httpd.service: 主进程退出,code=exited,status=1/FAILURE mag 16 23 :33:29 localhost.localdomain systemd [1]:无法启动 Apache HTTP 服务器。 -- 主题:单元 httpd.service 失败 -- 定义者:systemd -- 支持:lists.freedesktop.org/mailman/listinfo/systemd-devel
  • 在浏览器中我得到:Forbidden: You don't have permission to access /phpmyadmin on this server.
  • 我在我之前的评论中添加了一条注释,因为无法对其进行编辑。在收到Forbidden: You don't have permission to access /phpmyadmin on this server. 错误消息之前,我也没有被提示输入用户名和密码
【解决方案2】:

试试这个

替换

<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/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order Allow,Deny 
    Allow from all
</Directory>

添加以下行以方便访问:

Alias /phpmyadmin /usr/share/phpMyAdmin

【讨论】:

  • 在浏览器中我得到:Forbidden: You don't have permission to access /phpmyadmin on this server.
  • 我在我之前的评论中添加了一条注释,因为无法对其进行编辑。在收到Forbidden: You don't have permission to access /phpmyadmin on this server. 错误消息之前,我也没有被提示输入用户名和密码
  • 它应该通过 phpMyAdmin 登录屏幕提示输入用户名和密码。您是否尝试重新启动 Apache?
  • 是的,我重新启动了 Apache
【解决方案3】:

使用这个,它在 centOS 7 上为我修好了

<Directory /usr/share/phpMyAdmin/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>

【讨论】:

  • 在我的亚马逊 linux 上工作
【解决方案4】:

到目前为止,其他答案似乎主张完全替换 块,这不是必需的,并且可能会删除额外的设置,例如现在包含的“AddDefaultCharset UTF-8”。

2021 年更新

配置文件现在被简化了,所以只需要添加一行:

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

   Require local
   # ADD following line:
   Require all granted
</Directory>

原答案

要允许远程访问,您需要在 2.4 配置块中添加 1 行或在 2.2 中更改 2 行(取决于您的 apache 版本):

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

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

【讨论】:

  • 我可以确认这适用于 Centos 7。谢谢。
  • 适用于 EC2 实例。
  • 其他答案对我不起作用,确实如此。谢谢克里斯!!
  • 每个人:先试试这个,这是我发现的唯一一个在 EC2 linux 实例上工作的。谢谢你,克里斯!
【解决方案5】:

只需注释第一个目录中的所有行。或者您可以删除这些行,但最好保留以防以后您想添加一些限制,您将取消注释。

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

【讨论】:

    【解决方案6】:

    使用 XAMPP 时我的设置略有不同。在 httpd-xampp.conf 中,我必须进行以下更改。

    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
        #makes it so I can config the database from anywhere
        #change the line below
        Require all granted
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
    </Directory>
    

    我需要说明我在这方面是全新的,所以我只是在胡扯,但这就是我的工作方式。

    【讨论】:

      【解决方案7】:

      我的答案是基于收到 403 错误,尽管我在其他答案中提到的所有 Apache 设置都是正确的。

      这是一个全新的 Centos 7 服务器,结果发现问题不在于 Apache 设置,而是 PhpMyAdmin 根本没有提供服务。解决方案是安装 php 并将 php 指令添加到 apache.conf:

      • sudo yum install php php-mysql
      • vim /etc/httpd/conf/httpd.conf 添加类似
      • 的内容
      • 目录索引 index.php index.phtml index.html index.htm 也提供 php 索引文件 然后重启apache

      别忘了重启Apache服务器才能生效 - systemctl 重启 httpd.service

      我希望这会有所帮助。我首先认为我的问题是 Apache 指令,所以我在这里发布了我的解决方案。

      【讨论】:

        猜你喜欢
        • 2017-12-24
        • 2012-08-02
        • 1970-01-01
        • 1970-01-01
        • 2018-05-21
        • 1970-01-01
        • 1970-01-01
        • 2011-07-28
        • 2015-06-29
        相关资源
        最近更新 更多