Linux系統入門學習:在CentOS上安裝phpMyAdmin

來源:互聯網
上載者:User

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。根據你的偏好和需求,你可以從LAMP和LEMP中選擇一種安裝。

CentOS 6.5安裝配置LAMP

Ubuntu 13.04 安裝 LAMP\Vsftpd\Webmin\phpMyAdmin 服務及設定

CentOS 5.9下編譯安裝LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12)

RedHat 5.4下Web伺服器架構之源碼構建LAMP環境及應用PHPWind

LAMP源碼環境搭建WEB伺服器Linux+Apache+MySQL+PHP

基於Ubuntu 的LAMP 最佳化加固

另一個要求是允許在你的CentOS上安裝EPEL庫。如果你還沒設定過請猛戳這裡。

在CentOS6或7上安裝phpMyAdmin

一旦你設定了EPEL庫,你就能輕鬆地用以下命令安裝phpMyAdmin了。

在CentOS 7上:

  1. $ sudo yum install phpmyadmin

在CentOS 7上:

  1. $ 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"取而代之。重新改動過的設定檔如下所示。

  1. $ sudo vi /etc/httpd/conf.d/phpMyAdmin.conf
  1. .....
  2. <Directory/usr/share/phpMyAdmin/>
  3. AddDefaultCharset UTF-8
  4.  
  5. <IfModule mod_authz_core.c>
  6. # Apache 2.4
  7. <RequireAny>
  8. #Require ip 127.0.0.1
  9. #Require ip ::1
  10. Require all granted
  11. </RequireAny>
  12. </IfModule>
  13. <IfModule!mod_authz_core.c>
  14. # Apache 2.2
  15. OrderDeny,Allow
  16. DenyfromAll
  17. Allowfrom127.0.0.1
  18. Allowfrom::1
  19. </IfModule>
  20. </Directory>
  21.  
  22. <Directory/usr/share/phpMyAdmin/setup/>
  23. <IfModule mod_authz_core.c>
  24. # Apache 2.4
  25. <RequireAny>
  26. #Require ip 127.0.0.1
  27. #Require ip ::1
  28. Require all granted
  29. </RequireAny>
  30. </IfModule>
  31. <IfModule!mod_authz_core.c>
  32. # Apache 2.2
  33. OrderDeny,Allow
  34. DenyfromAll
  35. Allowfrom127.0.0.1
  36. Allowfrom::1
  37. </IfModule>
  38. </Directory>
  39. .....

最後,重啟httpd使改動生效。

  1. $ 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"。重新改動過的設定檔如下所示。

  1. $ sudo vi /etc/httpd/conf.d/phpmyadmin.conf
  1. <Directory"/usr/share/phpmyadmin">
  2. Order Deny,Allow
  3. # Deny from all
  4. Allow from 0.0.0.0
  5. </Directory>

下一步是將phpMyAdmin的設定檔用blowfish加密工具加密。這一步需要加密cookie裡的密碼來作為基於cookie的部分認證。

用文字編輯器開啟如下路徑所示的檔案並且用blowfish設定一個隨機密碼,如下所示。

  1. $ sudo vi /usr/share/phpmyadmin/config.inc.php
  1. $cfg['blowfish_secret']='kd5G}d33aXDc50!';/* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

最後,重啟httpd使改動生效。

  1. $ sudo service httpd restart
測試phpMyAdmin

測試phpMyAdmin是否設定成功,訪問這個頁面:http://<web-server-ip-addresss>/phpmyadmin

你應該能通過Web介面來記錄下任何MySQL使用者(比如root)和管理MySQL/MariaDB的資料庫/表。

疑難解答

這裡有一些在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,如下所示。

    1. $cfg['blowfish_secret']='kd5G}d33aXDc50!';/* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
    1. $ sudo service httpd restart (CentOS6)
    2. $ sudo systemctl restart httpd (CentOS7)
  3. 當你串連phpMyAdmin頁面時,你看見"Cannot load mcrypt extension. Please check your PHP configuration"錯誤資訊。

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

    1. $ sudo yum install php-mcrypt

    然後重啟httpd:

    1. $ sudo service httpd restart (CentOS6)
    2. $ sudo systemctl restart httpd (CentOS7)

LAMP架構協同應用的執行個體——phpMyAdmin

LAMP應用之phpMyAdmin、Wordpress

phpMyAdmin老出現登陸逾時解決方案

Ubuntu 安裝phpMyAdmin與Adminer

在LAMP基礎上實現SSL功能並安裝phpMyAdmin

Ubuntu 14.04 配置 LAMP+phpMyAdmin PHP(5.5.9)開發環境

phpMyAdmin 的詳細介紹:請點這裡
phpMyAdmin 的:請點這裡

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.