搭建phpMyAdmin来管理数据库

phpMyAdmin 对于新手来说是一个非常友好的 MySQL 管理工具,并且免费开源,配置很简单,接下来在 Linux 服务器上配置 phpMyAdmin 来管理 MySQL 数据库。

首先是准备工作,安装好 Nginx,PHP 和 MariaDB。

下载 phpMyAdmin

首先从 phpMyAdmin 官网下载安装包:

https://www.phpmyadmin.net/downloads/

选择 phpMyAdmin-5.1.1-all-languages.tar.gz 下载并解压到网站根目录:

1
wget https://files.phpmyadmin.net/phpMyAdmin/5.1.1/phpMyAdmin-5.1.1-all-languages.tar.gz -O - | tar -xz -C /var/www/flarum/public/

修改文件名为 phpMyAdmin:

1
2
cd /var/www/flarum/public/
mv phpMyAdmin-5.1.1-all-languages phpMyAdmin

配置 config 文件

1
vi /var/www/flarum/public/phpMyAdmin/libraries/config.default.php

1、修改访问网址

1
2
3
$cfg['PmaAbsoluteUri'] = '';`
修改成下面这样:
`$cfg['PmaAbsoluteUri'] = 'http://localhost/phpmyadmin/';

2、修改mysql主机信息

如果mysql和该phpmyadmin在同一服务器,则按默认localhost
$cfg['Servers'][$i]['host'] = 'localhost';

mysql端口,如果是默认3306,保留为空即可
$cfg['Servers'][$i]['port'] = '';

3、mysql用户名和密码

访问phpmyadmin使用的mysql用户名
$cfg['Servers'][$i]['user'] = 'root';

对应上述mysql用户名的密码
$cfg['Servers'][$i]['password'] = 'password';

4、认证方式

在此有四种模式可供选择,cookie,http,HTTP,config,建议选择cookie
$cfg['Servers'][$i]['auth_type'] = 'cookie';

5、设置短密码

如果认证方法设置为cookie,就需要设置短语密码,密码需要32个字节纯字母密码
$cfg['blowfish_secret'] = 'HSNKGVGGGSHSNKGVGGGSHSNKGVGGGS';

6、设置默认语言与编码

这里是选择语言,zh代表简体中文的意思
$cfg['DefaultLang'] = 'zh';

修改默认编码为国标
$cfg['DefaultConnectionCollation'] = 'gb2312_chinese_ci';

配置 nginx.conf 文件

1
vi /etc/nginx/nginx.conf

80或443端口下添加下面两个 location 即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
root /var/www/flarum/public;
index index.html index.htm index.php default.html default.htm default.php;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~* \.php$ {
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

启动nginx:systemctl start nginx

浏览器里输入域名后加上 /phpMyAdmin 后缀也就可以登录 phpMyAdmin 管理页面了。登录成功后将显示 phpMyAdmin 仪表板。

🔰本文标题: 搭建phpMyAdmin来管理数据库

🔞本文链接: https://193.gs/phpmyadmin/index.html

🌡️本文总热度