phpmyadmin“禁止:您无权访问此服务器上的 /phpmyadmin。”

phpmyadmin“禁止:您无权访问此服务器上的 /phpmyadmin。”

我需要修改文件/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/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order Allow,Deny 
    Allow from all
</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
     Allow 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>

当我进入 phpmyadmin 网页时,系统没有提示我输入用户和密码,而是显示错误消息:Forbidden: You don't have permission to access /phpmyadmin on this server。我的系统是 Fedora 20

答案1

查看您的 httpd 错误日志,看看它是否有有关拒绝的更多具体信息:/var/log/httpd/error_log

此外,如果 selinux 正在强制执行,则尝试将其关闭以进行测试:

$ sudo setenforce 0
$ getenforce

看看 /usr/share/phpMyAdmin 上的权限与 /var/www/html 上的权限

$ ls -ld /usr/share/phpMyAdmin /var/www/html

总是有 d'oh!检查一下...添加该配置后,您是否真的重新启动/重新加载了 Web 服务器?

$ apachectl restart

答案2

添加Allow from 10.10.10.10(替换10.10.10.10为你的 IP 地址),不要忘记重新启动 apacheservice httpd restart)。请随意看看我的,我已将其上传到 pastebin 供您使用:http://pastebin.com/hvU3SGs1(第 24、42 行)。

答案3

编辑文件: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)

答案4

您没有提到是否已配置.htaccess文件以使身份验证正常工作。您也应该发布其内容。

您需要将其放在/usr/share/phpMyAdmin目录下并且可以包含类似的内容:

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/apache2/.phpmyadmin.htpasswd
Require valid-user

DirectoryIndex index.php此外,您还需要在目录块中添加该行。

<Directory /usr/share/phpMyAdmin>
        Options FollowSymLinks
        DirectoryIndex index.php
        AllowOverride All
        [...]

您只需要自定义您的<Directory "/usr/share/phpMyAdmin/">部分和 .htaccess 文件。其余部分您可以保留原样以确保安全。

详细操作方法请见此处:如何在 CentOS 7 服务器上使用 Apache 安装和保护 phpMyAdmin

相关内容