phpMyAdmin + CentOS 6.0 - Forbidden

22

每当我想要访问phpMyAdmin时,总是会收到这个消息。

w3m localhost/phpmyadmin

Forbidden

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

Apache/2.2.15 (CentOS) Server at localhost Port 80

安装步骤:

rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2- 2.el6.rf.x86_64.rpm
yum install phpmyadmin

添加别名

vi /etc/httpd/conf.d/phpmyadmin.conf
Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpMyAdmin /usr/share/phpmyadmin
Alias /mysqladmin /usr/share/phpmyadmin

将cookie更改为http
vi /usr/share/phpmyadmin/config.inc.php
[...]
 /* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http';
[...]

重新启动

/etc/init.d/httpd restart

SELinux - /etc/httpd

drwxr-xr-x. root root system_u:object_r:httpd_config_t:s0 .
drwxr-xr-x. root root system_u:object_r:etc_t:s0       ..
drwxr-xr-x. root root system_u:object_r:httpd_config_t:s0 conf
drwxr-xr-x. root root system_u:object_r:httpd_config_t:s0 conf.d
lrwxrwxrwx. root root system_u:object_r:httpd_log_t:s0 logs -> ../../var/log/httpd
lrwxrwxrwx. root root system_u:object_r:httpd_modules_t:s0 modules -> ../../usr/lib64/httpd/modules
lrwxrwxrwx. root root system_u:object_r:httpd_config_t:s0 run -> ../../var/run/httpd

SELinux - /usr/share/phpmyadmin

drwxr-xr-x. root root   system_u:object_r:usr_t:s0       .
drwxr-xr-x. root root   system_u:object_r:usr_t:s0       ..
-rw-r--r--. root root   system_u:object_r:usr_t:s0       browse_foreigners.php
-rw-r--r--. root root   system_u:object_r:usr_t:s0       calendar.php
-rw-r--r--. root root   system_u:object_r:usr_t:s0       changelog.php
-rw-r--r--. root root   system_u:object_r:usr_t:s0       chk_rel.phph
.
.
.
-rw-r--r--. root root   system_u:object_r:usr_t:s0       view_create.php

OS

centos-release-6-0.el6.centos.5.x86_64
7个回答

31

请按照以下方法编辑您的httpd.conf文件:

# nano /etc/httpd/conf/httpd.conf
在此处添加以下行:
<Directory "/usr/share/phpmyadmin">
    Order allow,deny
    Allow from all
</Directory>

执行以下命令:

# service httpd restart
如果你的问题没有解决,那么禁用SELinux。

能否允许从类似于eth0的接口而不是全部接口进行连接?我正在使用带有NAT的VirtualBox。 - pouya
这个建议帮助解决了我的问题。<Directory "usr/share/phpmyadmin"> Order Deny,Allow Deny from all Allow from 127.0.0.1 </Directory> - JayHook
我尝试了这个方法,但它没有起作用。然后我将文件名config.sample.inc.php更改为config.inc.php,并编辑了文件,以便$cfg['Servers'][$i]['host'] =我的主机服务器的IP地址(而不是localhost),最终它起作用了。(我不知道我在做什么,但有人能否确认我所做的对于其他可能会遇到类似问题的人是否正确?) - moto
同时,您可以将此应用于特定的虚拟主机,其他人将会被拒绝访问(例如仅限管理员)。 - user1954544
事实上,这对我很有用,因为我的主机安装的是CentOS 6.8而不是7。 我只需要将代码从7(请参见Hyder的答案)切换到这个版本,它就可以正常工作了。 - Parapluie

31

对于我的CentOS 7服务器,上述任何配置都无法工作。经过几个小时的搜索,以下是对我有用的内容:

编辑文件phpMyAdmin.conf

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

并将其顶部替换为:

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

这应该是答案。完美地工作了。 - João Reis
另外还需要执行 "yum install php"。 - Sourav301
这刚刚救了我免受迅速恶化的头痛之苦-谢谢你! - GHandel
非常感谢。这对我有用。我已经尝试了2天来修复它。非常感谢。 :-) - Pawan Kumar
完美运行 - Bàn Chân Trần

8
我尝试了这里提供的所有答案:编辑phpMyAdmin.conf文件、更改phpmyadmin文件夹的selinux上下文、禁用selinux……但我仍然从Web服务器收到“Forbidden”的消息。
最后,在Edouard Thiel的帖子中,我找到了我缺少的内容(链接)$ yum install php 然后重启httpd: $ service httpd restart(CentOS 6主机) $ systemctl重启httpd(CentOS 7主机)
让我惊讶的是,为什么php在首次安装phpmyadmin时不作为依赖项安装。
谢谢,
Fred

这正是帮助我的原因,也是困扰我的原因 - 为什么PHP不是一个依赖项,即使它的名称要求它... - tymik
这对我有用。我以为我之前安装了php,但无论如何它应该给出一个不同于403的错误。 - Venura

3

我一直遇到同样的问题已经两天了,即使禁用了SELinux和一切都不能帮助解决问题。我意识到为了一个小修复而禁用安全可能并不明智。然后我发现了这篇文章 - http://wiki.centos.org/HowTos/SELinux/ 解释了SELinux的操作方式。所以我做了以下事情,并解决了我的问题。

  1. Enable access to your main phpmyadmin directory by going to parent directory of phpmyadmin (mine was html) and typing:

    chcon -v --type=httpd_sys_content_t phpmyadmin
    
  2. Now do the same for the index.php by typing:

    chcon -v --type=httpd_sys_content_t phpmyadmin/index.php
    

    Now go back and check if you are getting a blank page. If you are, then you are on the right track. If not, go back and check your httpd.config directory settings. Once you do get the blank page with no warnings, proceed.

  3. Now recurse through all the files in your phpmyadmin directory by running:

    chron -Rv --type=httpd_sys_content_t phpmyadmin/*
    

返回phpmyadmin页面查看是否已经得到所需内容。如果您正在运行可以从网络外部访问的Web服务器,请确保将SELinux重置为适当的安全级别。希望这能帮助您!


0

当我输入URL时,我遇到了同样的问题

https://www.nameDomain.com/phpmyadmin

出现了“禁止访问”的消息,是因为在/use/share/phpMyAdmin目录上有规则限制。我通过在这个文件/etc/httpd/conf.d/phpMyAdmin.conf的这个部分进行添加来解决它。

<Directory /usr/share/phpMyAdmin/>
    ....
</Directory>

这些规则的代码

<Directory /usr/share/phpMyAdmin/>
   Order Deny,Allow
   Deny from All
   Allow from 127.0.0.1
   Allow from ::1
   Allow from All
   ...
</Directory>

你保存文件之后,无论选择哪种方法,都要重启Apache服务,service httpd gracefulservice httpd restart,这取决于您的策略。

出于安全原因,您可以通过设置一个IP地址来指定一个连接,如果您的IP地址不变,则每次更改IP地址时也必须进行更改。

<Directory /usr/share/phpMyAdmin/>
   Order Deny,Allow
   Deny from All
   Allow from 127.0.0.1
   Allow from ::1
   Allow from 105.105.105.254 ## set here your IP address
   ...
</Directory>

0

上述提到的解决方案都不适用于我。以下是最终有效的方案:

#yum update
#yum install phpmyadmin

请注意,phpmyadmin 在几个小时前还能正常工作。我不知道发生了什么事。
之后,在浏览器中访问时,出现了一个错误,提示无法访问./config.inic.php。
#cd /usr/share/phpmyadmin/
#stat -c %a config.inic.php
#640
#chmod 644 config.inic.php

这表明文件权限为640,然后我将其更改为644。 最终,它起作用了。

记得重新启动httpd。

#service httpd restart

-1

我曾经遇到过同样的问题。

只有在我更改了php.ini变量

display_errors = Off

display_errors = On

Phpadmin才开始工作...太疯狂了...


那个配置文件与phpmyadmin无关。这可能是因为您之前编辑了正确的配置文件,但忘记重新启动httpd。然后在更改错误后重新启动,之前的编辑也被应用了。 - zozo

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