How to Install phpRedisAdmin on AWS EC2 using nginx

phpRedisAdmin是一個可以操作Redis資料的網頁應用程式,本篇將會教學如何在AWS EC2上面架設。

JeffChang
Nov 18, 2020

1. 安裝php

yum install -y git php-mbstring

因為在這我們使用的是EC2,實體是使用Amazon Linux,而Amazon自有已經打包好的套件,故php7.2是從這裡去抓哦

amazon-linux-extras install -y php7.2

2. 下載phpRedisAdmin至nginx/html目錄下

cd /usr/share/nginx/html
git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git
cd phpRedisAdmin
git clone https://github.com/nrk/predis.git vendor

3. 修改Nginx設定

這裡我不是直接修改/etc/nginx/nginx.conf,而是去修改/etc/nginx/conf.d/這目錄下的設定檔,因原本的80port已有服務使用,故這裡選擇偵聽8081port作為服務

server {
listen 8081;
server_name phpRedisAdmin;
root /usr/share/nginx/html;
index index.html index.htm index.php;

location / {
root /usr/share/nginx/html;
index index.php index.html;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

4. 讓Nginx重新載入設定檔

nginx -s reload

5. 修改PHP-FPM設定檔

修改/etc/php-fpm.d/www.conf,將以下原本被註解的部分解開,user與group改為nginx

listen.owner = nobody 
listen.group = nobody
listen.mode = 0666
user = nginx
group = nginx

然後啟動PHP-FPM

systemctl enable php-fpm
systemctl start php-fpm

6. 修改phpRedisAdmin設定檔

路徑:phpRedisAdmin/includes

原專案只有提供config.sample.inc.php範例設定檔,故這裡要複製這個檔案並重新命名為config.inc.php

cp config.sample.inc.php config.inc.php

比較重要的幾個設定說明

'servers' => array(
array(
'name' => '要顯示的Redis名稱',
'host' => 'AWS Redis Endpoint',
'port' => 6379,
'db' => 0,
'databases' => 0,
'filter' => '',
'seperator' => ':',
'flush' => false,
'charset' => 'utf-8',
'keys' => false,
'scansize' => 1000
),
),

name:要顯示的Redis名稱

host:AWS Redis Endpoint(若使用Elasticache的話),或放Redis Server IP

db:預設使用的DB(index),設定為0

databases:要秀出的db數量

filter:原本的設定是*(全撈),這樣會將資料全撈出來,若資料量大的話建議放空值,避免因資料量過大而頁面卡死

'login' => array(
// Username => Password
// Multiple combinations can be used
'admin' => array(
'password' => 'Ddim@123',
)
/*'guest' => array(
'password' => '',
'servers' => array(1) // Optional list of servers this user can access.
)*/
),
// Use HTML form/cookie-based auth instead of HTTP Basic/Digest auth 'cookie_auth' => true,

若要開啟登入設定,可以將上述的設定打開,並設定登入帳號與密碼,這樣進入頁面就需要登入才能使用

--

--

JeffChang
JeffChang

Written by JeffChang

Java Backend Engineer In DDIM.

No responses yet