Hướng dẫn cài đặt và cấu hình PHPMyAdmin với NGINX trên CentOS 7
PHPMyAdmin là một công cụ mã nguồn mở được sử dụng để quản trị MySQL. Ngoài việc cung cấp khả năng thực hiện các nhiệm vụ quản lý như tạo, chỉnh sửa, hoặc xóa cơ sở dữ liệu, quản lý người dùng và các quyền, phpMyAdmin cung cấp một giao diện người dùng đồ họa để làm tất cả những công việc này và nhiều hơn nữa.
Cài đặt phpMyAdmin dưới đây được thực hiện sau khi đã hoàn tất cài đặt NGINX, MySQL và PHP-FPM.
[root@iNET-VPS ~]# cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)
[root@iNET-VPS ~]# nginx -v
nginx version: nginx/1.10.1
[root@iNET-VPS ~]# php -v
PHP 7.0.7 (cli) (built: May 28 2016 07:53:22) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
[root@iNET-VPS ~]# mysql -V
mysql Ver 14.14 Distrib 5.6.31, for Linux (x86_64) using EditLine wrapper
Dưới đây là các bước thực hiện cài đặt phpMyAdmin với NGINX
Bước 1: Thêm EPEL Repository
[root@iNET-VPS ~]# rpm -iUvh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Bước 2: Install phpMyAdmin
Đầu tiên, bạn cập nhật các gói đã cài sẵn được cập nhật trước khi cài đặt bất cứ điều gì mới.
[root@iNET-VPS ~]# yum -y update
Sau đó chạy lệnh cài đặt
[root@iNET-VPS ~]# yum -y install phpmyadmin
Quá trình cài đặt sẽ hoàn tất.
Bước 3: Tạo 1 virtual host cho service phpMyAdmin
[root@iNET-VPS ~]# vi /etc/nginx/conf.d/phpmyadmin.conf
server {
listen 80 ;
server_name 202.92.5.166; <= Nhập địa chỉ máy chủ
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/phpMyAdmin/; <= thư mục gốc của PHPMyAdmin
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/phpMyAdmin/; <= thư mục gốc của PHPMyAdmin
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/phpMyAdmin/; <= thư mục gốc của PHPMyAdmin
fastcgi_pass unix:/var/run/php-main.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Sau đó lưu lại cấu hình bằng :wq và khởi động lại Nginx
[root@iNET-VPS ~]# systemctl restart nginx.service
[root@iNET-VPS ~]# systemctl restart php-fpm.service
Và truy cập và sử dụng phpMyAdmin với username và password của tài khoản root MySQL:
http://<đia-chỉ-ip-máy-chủ-của-bạn>/phpMyAdmin
Hướng dẫn xử lý một vài lỗi trong lần đầu chạy dịch vụ phpMyAdmin
Có vài cấu hình còn thiếu trên trang chủ của bảng điều khiển phpMyAdmin mà chúng ta cần phải cấu hình bằng cách thay đổi các tập tin cấu hình của phpMyAdmin. Hãy làm theo bước dưới đây để hoàn thành cấu hình thiếu.
Nếu bạn thấy thông báo lỗi sau ở dưới cùng của trang chủ phpMyAdmin của bạn sau khi đăng nhập đầu tiên của bạn,

Để khắc phục lỗi này, chúng tôi sẽ bỏ ghi chú bên dưới dòng từ tập tin cấu hình phpMyAdmin là thiết lập tên người dùng và mật khẩu kiểm soát.
[root@iNET-VPS ~]# vi /etc/phpMyAdmin/config.inc.php
Điều chỉnh các giá trị như bên dưới:
/* User used to manipulate with storage */
// $cfg['Servers'][$i]['controlhost'] = '';
// $cfg['Servers'][$i]['controlport'] = '';
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = 'pmapass';
/* Storage database and tables */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
$cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
$cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';
/* Contrib / Swekey authentication */
// $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf';
Tạo database và user cho phpMyAdmin
[root@iNET-VPS ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.6.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create user 'pma'@'localhost' identified by 'pmapass';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
Tiếp theo Import database
[root@iNET-VPS ~]# mysql -u root -p < /usr/share/phpMyAdmin/sql/create_tables.sql
Enter password:
Phân quyền cho User trong database:
[root@iNET-VPS ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.6.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> GRANT USAGE ON mysql.* TO 'pma'@'localhost' IDENTIFIED BY 'pmapass';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT SELECT ( Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv ) ON mysql.user TO 'pma'@'localhost'; GRANT SELECT ON mysql.db TO 'pma'@'localhost';
mysql> GRANT SELECT ON mysql.host TO 'pma'@'localhost';
mysql> GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv) ON mysql.tables_priv TO 'pma'@'localhost';
mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pma'@'localhost';mysql> exit;
Bye
Chúng ta đã thực hiện với tất cả các thiết lập và cấu hình của phpMyAdmin nay để thực hiện những thay đổi này, chúng ta phải khởi động lại nginx, mysql và dịch vụ php-fpm.
[root@iNET-VPS]#systemctl restart mysqld.service
[root@iNET-VPS]#systemctl restart nginx.service
[root@iNET-VPS]#systemctl restart php-fpm.service
Kiểm tra lại kết quả, sẽ không còn thấy các thông báo lỗi nữa:
Chúc bạn thực hiện thành công !