安装phpMyAdmin
phpMyAdmin是一个使用PHP语言编写的免费软件,旨在通过Web界面管理MySQL数据库。phpMyAdmin支持MySQL和MariaDB上的各种操作。用户可以通过Web界面执行数据库的常用操作(数据库管理,表,字段,索引,用户,权限,视图,函数等),以及直接执行任何SQL语句。
1. 创建phpMyAdmin Web目录
1 | [root@hming-server218-web ~ ] # mkdir /app/data/phpMyAdmin -p |
2. 将phpMyAdmin软件包解压到/app/data/phpMyAdmin 目录下
下载地址:https://www.phpmyadmin.net/downloads/
cd /home/web/www
wget https://files.phpmyadmin.net/phpMyAdmin/4.7.8/phpMyAdmin-4.7.8-all-languages.tar.gz
1 2 | # tar -zxf phpMyAdmin-4.7.8-all-languages.tar.gz # chown -R www:www /home/web/www/phpMyAdmin |
3. 修改nginx配置,创建一个server虚拟机配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | http { ...... # phpMyAdmin server { listen 8080; server_name _; charset UTF8; index index.html index.htm index.php index.jsp; root /home/web/www ; access_log /var/log/nginx/phpMyAdmin .log main; location /phpmyadmin/ { index index.html index.htm index.php; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000 ; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/web/www $fastcgi_script_name; include fastcgi_params; } } } |
4. 创建数据库root用户权限,允许php服务器使用root用户管理数据服务器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | [root@hming-server217-mdb ~ ] # mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 13 Server version: 10.1.20-MariaDB Source distribution Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> select user,host,password from mysql.user; +------+-----------+-------------------------------------------+ | user | host | password | +------+-----------+-------------------------------------------+ | root | localhost | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | | root | 127.0.0.1 | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | | root | ::1 | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | +------+-----------+-------------------------------------------+ 3 rows in set (0.00 sec) MariaDB [(none)]> grant all privileges on *.* to 'root' @ '10.0.6.218' identified by 'phpMyAdmin_123' ; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) |
5. 配置防火墙规则
1 2 3 4 5 | # iptables -I INPUT -p tcp --dport 3306 -s 10.0.6.0/24 -j ACCEPT 或者 firewall-cmd --permanent --zone=public --add-port=8080/tcp firewall-cmd --permanent --zone=public --add-port=3306/tcp |
6. 修改phpMyAdmin配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #cp/app/data/phpMyAdmin/libraries/config.default.php /app/data/phpMyAdmin/libraries/config.default.php.save # vim /app/data/phpMyAdmin/libraries/config.default.php /** * The 'COOKIE' auth_type uses AES algorithm to encrypt the password. If * at least one server configuration uses 'COOKIE' auth_type, enter here a * pass phrase that will be used by AES. The maximum length seems to be 46 * characters. * * @global string $cfg[ 'blowfish_secret' ] */ $cfg[ 'blowfish_secret' ] = '123456' ; /** * MySQL hostname or IP address * * @global string $cfg[ 'Servers' ][$i][ 'host' ] */ $cfg[ 'Servers' ][$i][ 'host' ] = '10.0.6.217' ; /** * MySQL port - leave blank for default port * * @global string $cfg[ 'Servers' ][$i][ 'port' ] */ $cfg[ 'Servers' ][$i][ 'port' ] = '3306' ; /** * Path to the socket - leave blank for default socket * * @global string $cfg[ 'Servers' ][$i][ 'socket' ] */ $cfg[ 'Servers' ][$i][ 'socket' ] = '' ; /** * Authentication method (valid choices: config, http, signon or COOKIE) * * @global string $cfg[ 'Servers' ][$i][ 'auth_type' ] */ $cfg[ 'Servers' ][$i][ 'auth_type' ] = 'COOKIE' ; /** * HTTP Basic Auth Realm name to display (only used with 'HTTP' auth_type) * * @global string $cfg[ 'Servers' ][$i][ 'auth_http_realm' ] */ $cfg[ 'Servers' ][$i][ 'auth_http_realm' ] = '' ; /** * MySQL user * * @global string $cfg[ 'Servers' ][$i][ 'user' ] */ $cfg[ 'Servers' ][$i][ 'user' ] = 'root' ; /** * MySQL password (only needed with 'config' auth_type) * * @global string $cfg[ 'Servers' ][$i][ 'password' ] */ $cfg[ 'Servers' ][$i][ 'password' ] = 'phpMyAdmin_123' ; |
参数解释参考:https://wenku.baidu.com/view/0b327800bed5b9f3f90f1c2d.html?rec_flag=&mark_pay_doc=2&mark_rec_page=1&mark_rec_position=4&clear_uda_param=1
7. 登录phpMyAdmin Web管理界面,打开http://10.0.6.218:8000/phpMyAdmin/
输入数据库用户和密码
输入密码后报错参考:http://blog.csdn.net/qq_15574035/article/details/76576990
测试创建数据库
配置phpMyAdmin增加Nginx登录身份验证功能
1. 修改Nginx配置文件,在/phpMyAdmin/处增加允许访问规则和auth_basic身份验证配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # phpMyAdmin server { listen 8000; server_name 10.0.6.218; charset UTF8; index index.html index.htm index.php index.jsp; root /app/data ; access_log /var/log/nginx/phpMyAdmin .log main; location /phpMyAdmin/ { allow 10.0.6.0 /24 ; deny all; auth_basic "Auth" ; auth_basic_user_file /usr/local/nginx/ .htpassword; index index.html index.htm index.php; } location ~ \.php$ { fastcgi_pass unix: /var/lib/php/php-fcgi .sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /app/data $fastcgi_script_name; include fastcgi_params; } } |
2. 使用htpasswd创建用户(HM)和密码
1 2 3 4 5 6 7 | [root@hming-server218-web ~ ] # yum install httpd [root@hming-server218-web ~ ] # htpasswd -c /usr/local/nginx/.htpassword HM New password: Re- type new password: Adding password for user HM [root@hming-server218-web ~ ] # ls -l /usr/local/nginx/.htpassword -rw-r--r-- 1 root root 41 Jun 6 18:04 /usr/local/nginx/ .htpassword |
3. 重新访问phpMyAdmin,再次登录需要进行身份验证,以后的每一次登录都将需要进行此验证
输入用户和密码