phpMyAdmin允许远程用户

时间:2014-05-16 21:17:25

标签: php mysql phpmyadmin mariadb

我需要修改文件/etc/httpd/conf.d/phpMyAdmin.conf 为了允许远程用户(不仅是localhost)登录

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

7 个答案:

答案 0 :(得分:78)

到目前为止,其他答案似乎主张完全替换&lt; Directory /&gt;阻止,这是不需要的,并可能删除额外的设置,如“AddDefaultCharset UTF-8&#39;现在包括在内。

要允许远程访问,您需要在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>

答案 1 :(得分:20)

使用它,它已经为我修复了,超过了%OS 7

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

答案 2 :(得分: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。

答案 3 :(得分: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

答案 4 :(得分:2)

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

public class MainActivity extends AppCompatActivity{

}

更改为

Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
    AllowOverride AuthConfig
    Require local
    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>

我需要声明我在这方面是全新的,所以我只是在瞎逛,但这就是我的工作方式。

答案 5 :(得分: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>

答案 6 :(得分: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指令,所以我在这里发布我的解决方案。