【问题标题】:phpMyAdmin + CentOS 6.0 - ForbiddenphpMyAdmin + CentOS 6.0 - 禁止
【发布时间】:2011-11-21 22:13:58
【问题描述】:

当我想访问我的 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

操作系统

centos-release-6-0.el6.centos.5.x86_64

【问题讨论】:

    标签: phpmyadmin centos selinux


    【解决方案1】:

    我在录制 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>
    

    【讨论】:

      【解决方案2】:

      上述解决方案均不适合我。以下是最终奏效的方法:

      #yum update
      #yum install phpmyadmin
      

      请注意,phpmyadmin 几个小时前就开始工作了。我不知道发生了什么。

      在此之后,转到浏览器,我收到一个错误,上面写着./config.inic.php can't be accessed

      #cd /usr/share/phpmyadmin/
      #stat -c %a config.inic.php
      #640
      #chmod 644 config.inic.php
      

      这说明文件权限是640,然后我改成644。 终于成功了。

      记得重启httpd。

      #service httpd restart
      

      【讨论】:

        【解决方案3】:

        以上配置都不适用于我的 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>
        

        【讨论】:

        • 这应该是答案。完美运行
        • 另外必须做“yum install php”
        • 这让我摆脱了快速恶化的头痛——谢谢!
        • 非常感谢。它对我有用。过去 2 天我一直在尝试解决此问题。非常感谢。 :-)
        • 完美运行
        【解决方案4】:

        我尝试了此处提供的所有答案:编辑 phpMyAdmin.conf,更改 phpmyadmin 文件夹的 selinux 上下文,禁用 selinux...但我仍然从 Web 服务器获得“禁止”。

        我终于在 Edouard Thiel 的帖子 here 中找到了我所缺少的东西:

        $ yum install php

        然后重启httpd:

        $ service httpd restart => 用于 centos 6 热点

        $ systemctl restart httpd => 用于 centos 7 主机

        令我惊讶的是,为什么一开始没有将 php 作为 phpmyadmin 的依赖项安装。

        问候, 弗雷德

        【讨论】:

        • 这正是帮助我和困扰我的原因 - 为什么 php 不是一个包的依赖项,即使它的名字也需要它......
        • 这对我有用。我以为我以前安装了 php,但无论如何它应该给出除了 403 以外的不同错误
        【解决方案5】:

        我这两天有同样的问题。禁用 SELinux 和一切,但没有任何帮助。而且我意识到为一个小修复禁用安全性可能并不聪明。然后我看到了这篇文章 - http://wiki.centos.org/HowTos/SELinux/,它解释了 SELinux 的运行方式。所以这就是我所做的,它解决了我的问题。

        1. 通过转到 phpmyadmin 的父目录(我的是 html)并键入以下内容来启用对您的主 phpmyadmin 目录的访问:

          chcon -v --type=httpd_sys_content_t phpmyadmin
          
        2. 现在对 index.php 执行相同的操作,输入:

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

          现在返回并检查您是否得到一个空白页。如果你是,那么你就在正确的轨道上。如果没有,请返回并检查您的 httpd.config 目录设置。得到没有警告的空白页后,继续。

        3. 现在通过运行递归遍历 phpmyadmin 目录中的所有文件:

          chron -Rv --type=httpd_sys_content_t phpmyadmin/*
          

        回到你的 phpmyadmin 页面,看看你是否看到了你需要的东西。 如果您正在运行可从网络外部访问的 Web 服务器,请确保将 SELinux 重置为正确的安全级别。希望这会有所帮助!

        【讨论】:

          【解决方案6】:

          我有同样的问题。

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

          display_errors = 关闭

          display_errors = 开启

          Phpadmin 开始工作了.. 疯了....

          【讨论】:

          • 那个conf与phpmyadmin无关。这可能是因为您之前编辑了正确的 conf 但忘记重新启动 httpd。然后在更改错误后重新启动并应用之前的编辑。
          【解决方案7】:

          如下编辑您的 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
          • 这个建议帮助解决了我的问题。 Order Deny,Allow Deny from all Allow from 127.0.0.1
          • 我试过了,但没有用。然后我将文件名 config.sample.inc.php 更改为 config.inc.php 并编辑了文件,以便 $cfg['Servers'][$i]['host'] = 我的主机服务器的 IP 地址(而不是localhost),它终于奏效了。 (我不知道我在做什么,但有人可以确认我所做的对于可能发现自己处于我位置的其他人是否正确?)
          • 你也可以为特定的虚拟主机添加这个,其他人将被拒绝(例如仅限管理员)
          • 这实际上对我有用,因为我的主机设置了一台使用 CentOS 6.8 而不是 7 的机器。我只需将 7 的代码(请参阅 Hyder 的回答)切换到此,它运行良好。
          猜你喜欢
          • 2015-10-29
          • 2012-04-05
          • 1970-01-01
          • 2021-06-11
          • 2013-01-04
          • 2017-01-26
          • 1970-01-01
          • 2017-07-01
          相关资源
          最近更新 更多