如何在CentOS上安裝phpMyAdmin

jopen 9年前發布 | 45K 次閱讀 數據庫管理工具 phpMyAdmin

phpMyAdmin是一款以PHP為基礎,基于Web的MySQL/MariaDB數據庫管理工具。雖然已經存在著一些諸如Adminer的輕量級數據庫管理工具, 但是phpMyAdmin還是更加廣泛應用于網站管理員之中來進行各種MySQL/MariaDB的管理任務。它支持幾乎所有MySQL數據庫/表的相關操作,比如瀏覽、創建、復制、刪除、重命名、更改,還有MySQL用戶/權限管理和數據庫導入/導出。以下就是如何在CentOS 6或7上安裝phpMyAdmin

如何在CentOS上安裝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://<web-server-ip-addresss>/phpmyadmin

如何在CentOS上安裝phpMyAdmin

你應該能通過Web界面來記錄下任何MySQL用戶(比如root)和管理MySQL/MariaDB的數據庫/表。

如何在CentOS上安裝phpMyAdmin

疑難解答

這里有一些在CentOS上安裝phpMyAdmin的過程中遇到的一些問題解決方法。

  1. 當你在瀏覽器里嘗試連接phpMyAdmin頁面的時候,你看到"403 Forbidding"錯誤:

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

    發生這種錯誤是因為phpMyAdmin默認阻止了IP地址遠程連接。要修復這種錯誤,你需要編輯它的配置文件來允許遠程連接。具體操作見上。

  2. 當你連接phpMyAdmin頁面時,你看見"The configuration file now needs a secret passphrase (blowfish_secret)."信息,并且你無法登錄。

    要修復這種錯誤,你需要編輯 /usr/share/phpmyadmin/config.inc.php 這個文件來添加一個隨機的blowfish密碼,然后重啟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) 
  3. 當你連接phpMyAdmin頁面時,你看見"Cannot load mcrypt extension. Please check your PHP configuration"錯誤信息。

    要修復這種錯誤,要安裝下面這個包:

    $ sudo yum install php-mcrypt 

    然后重啟httpd:

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

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

譯者:ZTinoZ 校對:wxy

本文由 LCTT 原創翻譯,Linux中國 榮譽推出

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!