phpMyAdmin允许远程用户

38

我需要修改文件/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>

1
你想让它对所有人开放还是只针对特定的IP地址? - Haru
我想为每个人打开它。 - Germano Massullo
你最终解决了这个问题吗? - Alexandre Bourlier
1
@Euloiix 不行,因为运行PHPmyAdmin的虚拟机已不可用。 - Germano Massullo
7个回答

85
到目前为止,其他答案似乎主张完全替换块,这是不必要的,可能会删除现在包含的额外设置,比如“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>

6
我可以确认这个方法适用于Centos 7。谢谢。 - Syaiful Nizam Yahya
1
适用于EC2实例。 - driftking9987
其他答案对我不起作用,这个可以。谢谢Chris!! - Naguib Ihab
大家好:首先尝试这个,这是我在EC2 Linux实例上找到的唯一有效的方法。感谢Chris! - Emmet Arries
这对我来说也适用于Centos 7的VPS。 - Pranta Saha

21

我使用这个方法,它在CentOS 7上为我解决了问题。

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

1
在我的Amazon Linux上运行正常。 - Kanak Singhal

4

替换第一个<directory>标签中的内容。

删除:

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


5月16日23:33:29 localhost.localdomain httpd[2212]: httpd: /etc/httpd/conf.d/phpMyAdmin.conf的第11行语法错误,导致/etc/httpd/conf/httpd.conf的第353行也出现了语法错误。 5月16日23:33:29 localhost.localdomain systemd[1]: httpd.service主进程退出,代码=已退出,状态=1/失败。 5月16日23:33:29 localhost.localdomain systemd[1]: 无法启动Apache HTTP服务器。 -- 主题:Unit httpd.service失败 -- 定义者:systemd -- 支持:http://lists.freedesktop.org/mailman/listinfo/systemd-devel - Germano Massullo
在浏览器中,我得到了以下信息:“禁止访问:您没有权限访问此服务器上的/phpmyadmin。” - Germano Massullo
2
我在之前的评论中添加了一条注释,因为无法编辑它。在收到“Forbidden: You don't have permission to access /phpmyadmin on this server.”错误消息之前,我既没有被提示输入用户名和密码。 - Germano Massullo

3

我使用的是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>

我需要说明的是,我在这方面是新手,所以只是试试看,但这就是我让它工作的方法。


3

请尝试这个

替换

<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

1
在浏览器中,我得到了以下信息:“禁止访问:您没有权限访问此服务器上的/phpmyadmin。” - Germano Massullo
我在之前的评论中添加了一条注释,因为无法编辑它。在收到“Forbidden: You don't have permission to access /phpmyadmin on this server.”错误消息之前,我既没有被提示输入用户名和密码。 - Germano Massullo
它应该使用phpMyAdmin登录界面提示输入用户名和密码。你尝试过重新启动Apache吗? - John Guan
是的,我重新启动了Apache。 - Germano Massullo

0

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

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

0

我的答案是基于我遇到了403错误,尽管我已经正确设置了其他答案中提到的所有Apache设置。

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

  • sudo yum install php php-mysql
  • vim /etc/httpd/conf/httpd.conf 添加以下内容:
  • DirectoryIndex index.php index.phtml index.html index.htm 以便还可以提供php索引文件 然后重新启动apache

别忘了重新启动Apache服务器以生效 - systemctl restart httpd.service

希望这可以帮助到你。我最初认为我的问题是Apache指令,所以我在这里发布了我的解决方案。


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