在CentOS 7上安裝phpMyAdmin

來源:互聯網
上載者:User

標籤:

原文 在CentOS 7上安裝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上安裝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. <IfModule mod_authz_core.c>
  5. # Apache 2.4
  6. <RequireAny>
  7. #Require ip 127.0.0.1
  8. #Require ip ::1
  9. Require all granted
  10. </RequireAny>
  11. </IfModule>
  12. <IfModule !mod_authz_core.c>
  13. # Apache 2.2
  14. Order Deny,Allow
  15. Deny from All
  16. Allow from 127.0.0.1
  17. Allow from ::1
  18. </IfModule>
  19. </Directory>
  20. <Directory /usr/share/phpMyAdmin/setup/>
  21. <IfModule mod_authz_core.c>
  22. # Apache 2.4
  23. <RequireAny>
  24. #Require ip 127.0.0.1
  25. #Require ip ::1
  26. Require all granted
  27. </RequireAny>
  28. </IfModule>
  29. <IfModule !mod_authz_core.c>
  30. # Apache 2.2
  31. Order Deny,Allow
  32. Deny from All
  33. Allow from 127.0.0.1
  34. Allow from ::1
  35. </IfModule>
  36. </Directory>
  37. . . . . .

最後,重啟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:///phpmyadmin

 

 

 

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

 

 

 

疑難解答這裡有一些在CentOS上安裝phpMyAdmin的過程中遇到的一些問題解決方案。

當你在瀏覽器裡嘗試串連phpMyAdmin頁面的時候,你看到”403 Forbidding”錯誤:

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

發生這種錯誤是因為phpMyAdmin預設阻止了IP地址遠端連線。要修複這種錯誤,你需要編輯它的設定檔來允許遠端連線。具體操作見上。

當你串連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 (CentOS 6)$ sudo systemctl restart httpd (CentOS 7)

當你串連phpMyAdmin頁面時,你看見”Cannot load mcrypt extension. Please check your PHP configuration”錯誤資訊。

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

  1. $ sudo yum install php-mcrypt

然後重啟httpd:

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

在CentOS 7上安裝phpMyAdmin

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.