在CentOS 7上安裝phpMyAdmin

原文 在CentOS 7上安裝phpMyAdminphp

phpMyAdmin是一款以PHP爲基礎,基於Web的MySQL/MariaDB數據庫管理工具。雖然已經存在着一些諸如Adminer的輕量級數據庫管理工具, 可是phpMyAdmin仍是更加普遍應用於網站管理員之中來進行各類MySQL/MariaDB的管理任務。它支持幾乎全部MySQL數據庫/表的相關操做,好比瀏覽、建立、複製、刪除、重命名、更改,還有MySQL用戶/權限管理和數據庫導入/導出。如下就是如何在CentOS 6或7上安裝phpMyAdminhtml

 

105616takjivihinhipzmy

 

 

前提在CentOS上安裝phpMyAdmin,你第一步須要架設一臺Web服務器(如Apache或nginx),安裝好MySQL/MariaDB數據庫和PHP。根據你的偏好和需求,你能夠從LAMP和LEMP中選擇一種安裝。nginx

另外一個要求是容許在你的CentOS上安裝EPEL庫。若是你還沒設置過請猛戳這裏。shell

在CentOS6或7上安裝phpMyAdmin一旦你設置了EPEL庫,你就能輕鬆地用如下命令安裝phpMyAdmin了。數據庫

CentOS 7上:centos

  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」取而代之。從新改動過的配置文件以下所示。cookie

  1. $ sudo vi /etc/httpd/conf.d/phpMyAdmin.conf
  2. . . . . .
  3. <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 >
  4. . . . . .

最後,重啓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

 

105620ud2pex6zfm2mmopf

 

 

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

 

105622slmakqel8lqm0hkl

 

 

疑難解答這裏有一些在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)
相關文章
相關標籤/搜索