安裝

CentOS 7 本身提供的 phpMyAdmin 版本過舊,有安全性疑慮,故採用手動方式安裝。

安裝之前

安裝之前 先執行下面指令確認可以使用的 php 延伸模組

yum install -y wget php php-pdo php-pecl-zip php-json php-common php-fpm php-mbstring php-cli php-mysqlnd

下載

wget https://files.phpmyadmin.net/phpMyAdmin/4.9.2/phpMyAdmin-4.9.2-all-languages.tar.gz

解壓縮

tar -zxvf phpMyAdmin-4.9.2-all-languages.tar.gz

移動目錄

mv phpMyAdmin-4.9.2-all-languages /usr/share/phpMyAdmin

設定

複製設定檔

cp -pr /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php

編輯設定檔

vi /usr/share/phpMyAdmin/config.inc.php

找到下面這行 $cfg[‘blowfish_secret’] 並填入任意一串 32 個字串給 cookie 用

$cfg['blowfish_secret'] = 'ao95yEvJ;V,1PzSlSyFw1yMJ}WmG[8e6'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

建立一個 table 給 phpMyAdmin 用

mysql < /usr/share/phpMyAdmin/sql/create_tables.sql -u root -p

編輯 httpd.conf 設定 phpMyAdmin ,vi /etc/httpd/conf.d/phpMyAdmin.conf 填寫下面資料進去:

<Directory /usr/share/phpMyAdmin/>
    AddDefaultCharset UTF-8
    <IfModule mod_authz_core.c>
        # Apache 2.4
        <RequireAny> 
        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 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>

建立暫存檔 tmp 目錄 並將目錄權限改為777 及 owner 改為 apache

mkdir /usr/share/phpMyAdmin/tmp
chmod 777 /usr/share/phpMyAdmin/tmp
chown -R apache:apache /usr/share/phpMyAdmin
chmod 660 /usr/share/phpMyAdmin/config.inc.php

重啟 Apache 試著打開安裝好的 phpMyAdmin 網頁 (http://你的ip/phpMyAdmin)

最後修改日期: 2019 年 12 月 19 日