TranslateProject/sources/tech/20141118 Linux FAQs with Answers--How to install phpMyAdmin on CentOS.md
2014-11-28 17:35:37 +08:00

6.4 KiB
Raw Blame History

Linux问答时间--如何在CentOS上安装phpMyAdmin

问题:我正在CentOS上运行一个MySQL/MariaDB服务并且我想要通过网络接口来用phpMyAdmin来管理数据库。在CentOS上安装phpMyAdmin的最佳方法是什么

phpMyAdmin是一款以PHP为基础基于Web的MySQL/MariaDB数据库管理工具。虽然已经存在着一些诸如Adminer的轻量级数据库管理工具, 但是phpMyAdmin还是更加广泛应用于网站管理员之中来进行各种MySQL/MariaDB的管理任务。它支持几乎所有MySQL数据库表的相关操作比如浏览、创建、复制、删除、重命名、更改还有MySQL用户/权限管理和数据库导入/导出。以下就是如何在CentOS 6或7上安装phpMyAdmin

前提

在CentOS上安装phpMyAdmin你第一步需要架设一台Web服务器(如Apache或nginx)安装好MySQL/MariaDB数据库和PHP。根据你的偏好和需求你可以从LAMPLEMP中选择一种安装。

另一个要求是允许在你的CentOS上安装EPEL库。如果你还没设置过请猛戳这里

在CentOS6或7上安装phpMyAdmin

一旦你设置了EPEL库你就能轻松地用以下命令安装phpMyAdmin了。

在CentOS 7上:

$ sudo yum install phpmyadmin 

在CentOS 7上:

$ sudo yum install phpmyadmin php-mcrypt 

在CentOS 7上配置phpMyAdmin

默认情况下CentOS 7上的phpMyAdmin只允许从回环地址(127.0.0.1)访问。为了能远程连接,你需要改动它的配置。

用文本编辑器打开phpMyAdmin的配置文件(路径:/etc/httpd/conf.d/phpMyAdmin.conf),找出并注释掉带有"Require ip XXXX"字样的代码行。会有四处这样的代码行,用"Require all granted"取而代之。重新改动过的配置文件如下所示。

$ sudo vi /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>
 
<Directory /usr/share/phpMyAdmin/setup/>
   <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>
. . . . .

最后重启httpd使改动生效。

$ sudo systemctl restart httpd 

在CentOS 6上配置phpMyAdmin

默认情况下CentOS 6上的phpMyAdmin是禁止从每个IP地址访问的。为了能远程连接你需要改动它的配置。

用文本编辑器打开phpMyAdmin的配置文件(路径:/etc/httpd/conf.d/phpMyAdmin.conf),找出并注释掉"Deny from all"字样的代码行。然后把"Allow from 127.0.0.1"字样的代码行改成"Allow from 0.0.0.0"。重新改动过的配置文件如下所示。

$ sudo vi /etc/httpd/conf.d/phpmyadmin.conf 

<Directory "/usr/share/phpmyadmin">
  Order Deny,Allow
#  Deny from all
  Allow from 0.0.0.0
</Directory>

下一步是将phpMyAdmin的配置文件用blowfish加密工具加密。这一步需要加密cookie里的密码来作为基于cookie的部分认证。

用文本编辑器打开如下路径所示的文件并且用blowfish设置一个随机密码如下所示。

$ sudo vi /usr/share/phpmyadmin/config.inc.php 

$cfg['blowfish_secret'] = 'kd5G}d33aXDc50!'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

最后重启httpd使改动生效。

$ sudo service httpd restart 

测试phpMyAdmin

测试phpMyAdmin是否设置成功访问这个页面http:///phpmyadmin

你应该能通过Web界面来记录下任何MySQL用户(比如root)和管理MySQL/MariaDB的数据库/表。

疑难解答

Here are a few troubleshooting tips during phpMyAdmin installation on CentOS.

  1. When you are trying to access phpMyAdmin page in web browser, you are getting "403 Forbidding" error with:

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

This error is happening because the default setting of phpMyAdmin blocks access from a remote IP address. To fix this error, you need to edit its configuration to allow remote access. See the above for more detail.

  1. When you access phpMyAdmin page, you are seeing "The configuration file now needs a secret passphrase (blowfish_secret)." message, and you cannot login.

To fix this error, you need to edit /usr/share/phpmyadmin/config.inc.php to add a random blowfish password as follows, and restart httpd.

$cfg['blowfish_secret'] = 'kd5G}d33aXDc50!'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

$ sudo service httpd restart (CentOS 6)
$ sudo systemctl restart httpd (CentOS 7) 
  1. When you access phpMyAdmin page, you are getting "Cannot load mcrypt extension. Please check your PHP configuration" error message.

To solve this error, install the following package:

$ sudo yum install php-mcrypt 

and restart httpd:

$ sudo service httpd restart (CentOS 6)
$ sudo systemctl restart httpd (CentOS 7) 

via: http://ask.xmodulo.com/install-phpmyadmin-centos.html

译者:ZTinoZ 校对:校对者ID

本文由 LCTT 原创翻译,Linux中国 荣誉推出