腾讯云服务器 WordPress 镜像下的 phpMyAdmin 5.1 安装教程
本文最后更新于 1002 天前,其中的信息可能已经有所发展或是发生改变。

教程所用环境:CentOS 7/PHP 7.4/Negix 18.0/MariaDB 10.5/WordPress 5.9/BT Panel 7.9/phpMyAdimn 5.1

1. 为什么要手动安装

本人使用的是腾讯云所提供的 WordPress 镜像,这个镜像中,是默认携带了宝塔面板的。如图 1 所示。

腾讯云WordPress镜像默认配置
图 1 腾讯云 WordPress 镜像默认配置

因此,我们可以选择从宝塔面板中的应用商店来一键自动安装 phpMyAdmin。但是,实际上事实并没有我们想象的那么美好。

本人在安装好这个镜像后,将 WordPress 升级到了 5.9,并且宝塔面板也升级到了 7.9。随后使用宝塔面板安装 phpMyAdmin 后,就会发现,PHP 服务离奇的停止了运行,如图 2 所示。

图 2 安装 phpMyAdmin 后,PHP 无故停止

同时,这时在浏览器上输入 http://ip:888,会显示”502 bad gateway“错误,无法正常使用,如图 3 所示。且按照网上所说的更改 phpMyAdmin 中的 PHP 版本设置后依然无法正常访问。

图 3 502 报错界面

在上网查询各种解决方法后未果后,本人出于好奇,手贱的重启了一次服务器。结果发现 phpMyAdmin 仍然无法正常使用,但是 PHP 服务正常运行。同时 MySQL 服务停止运行,并且无法正常启动,如图 4 所示。由于本人对 Linux 数据库运维等并不熟悉,因此目前尚不知道原因。

图 4 MySQL 服务停止运行

可见,目前宝塔面板安装 phpMyAdmin 后可能会出现一些问题,但是手动安装就不会有这样的问题产生。因此在重置服务器后本人选择手动安装 phpMyAdmin。

2. 安装方法

2.1 下载并解压 phpMyAdmin

首先前往 phpMyAdmin 官方网站下载源码包,建议下载 tar.gz 格式的源码包,并使用宝塔面板、FTP 协议或者 MobaXterm 软件上传到服务器中。或者直接使用 Linux 命令下载。

转到下载目录:

cd /usr/local/src

使用 wet 命令进行下载:

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

解压文件到当前目录:

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

2.2 将 phpMyAdmin 移动到网站目录下

在腾讯云 ESC 自带的 WordPress 镜像中,已经默认为 phpMyAdmin 准备好了一个安装目录,具体可以通过下面的方法来查看:

(1). 首先登录腾讯云服务器控制台,转到应用管理,上面会显示 Negix 配置文件的默认位置,如图 5。

输入下面的命令,即可查看详细的 Negix 配置:

vim /www/server/nginx/conf/nginx.conf

找到有着这样内容的几行(输入:q 退出 vim):

server {
listen 888;
root /yourdirectory/phpmyadmin;

其中,”root“后面的目录,就是该镜像为 phpMyAdmin 准备的默认安装目录。

输入下面的命令,将解压后的文件移动到默认的目录下。(如果你使用的不是腾讯云服务器加上该镜像,而是任意一台其他的服务器,那么你可以自行创建一个安装目录,并将 phpMyAdmin 移动到这个目录下,并在最后一步的解析时将 root 后的路径设置成这个你自己创建的安装目录即可)

mv phpMyAdmin-5.1.3-all-languages /yourdirectory/phpmyadmin

至此,phpMyAdmin 安装成功

3. phpMyAdmin 配置方法

首先进入到你自己的 phpMyAdmin 的安装目录下,并转到 ./libraries 文件夹下:

cd /yourdirectory/phpmyadmin/libraries

编辑 config.default.php 文件:

vim config.default.php

修改如下几处(数据库用户名和密码可以用腾讯云应用管理处提供的命令来查询):

/**
* MySQL hostname or IP address
*
* @global string $cfg['Servers'][$i]['host']
*/
$cfg['Servers'][$i]['host'] = '127.0.0.1';
/**
* MySQL user
*
* @global string $cfg['Servers'][$i]['user']
*/
$cfg['Servers'][$i]['user'] = '你的数据库用户名';
/**
* MySQL password (only needed with 'config' auth_type)
*
* @global string $cfg['Servers'][$i]['password']
*/
$cfg['Servers'][$i]['password'] = '你的数据库密码';

ESC,:wq 保存,配置完成。

4. 配置 Negix 解析 phpMyAdmin

完成上一步后,此时在浏览器中输入 http://ip:888,还是会显示 502 错误。原因是腾讯云镜像虽然给我们准备好了一个推荐的安装目录,但是并没有帮我们做好解析工作,因此 Negix 中的默认解析配置还存在问题,需要我们自己重新配置解析。

重新打开 Negix 配置文件,找到上面提到的那个 server,将这个 server 删掉,并替换成以下内容(如果你使用的不是腾讯云服务器加上该镜像,那么只需要将这个配置中 root 后面的目录换成你自己创建的安装目录即可):

server {
listen 888; # 如果你不想使用888这个端口访问phpMyAdmin,请将其改为其他端口,如12345
root /yourdirectory/phpmyadmin; # 这里写你的phpMyAdmin的根目录
index index.html index.php;
location / {
}
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;
}
}

重启 Negix

systemctl restart nginx

浏览器访问 http://ip:888,发现可以正常访问,如图 5(登录用户名和密码即为 MySQL 数据库的用户名和密码)。

图 5 phpMyAdmin 安装配置成功

5. 其他的一些问题

(1). 登陆后报错:” 缺少变量 $cfg [‘TempDir’] (./tmp/)无法访问,phpMyAdmin 无法缓存模板文件,所以会运行缓慢 “,如图 6。

解决方法 :进入 phpMyAdmin 的安装目录,新建 tmp 文件夹即可。

cd /yourdirectory/phpmyadmin
mkdir tmp
chmod 777 tmp

关闭页面后再次打开,问题解决。

(2). 登录后报错:” 配置文件现在需要一个短语密码。”,如图 7。

图 7 配置文件现在需要一个短语密码

解决方法 :打开 phpMyAdmin 下的配置文件 (/ 你的 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'] = '你设置的密码,最好有32位,不然还会报错说密码长度太短';

关闭页面后再次打开,问题解决。

(3). “phpMyAdmin 高级功能尚未完全设置,部分功能未激活”,如图 8。

图 8 phpMyAdmin 高级功能尚未完全设置,部分功能未激活

解决方法

首先找到 / 你的 phpMyAdmin 安装目录 /sql/create_tables.sql 文件,并想办法把它下载到你的电脑上(可以用宝塔面板)。

浏览器访问 http://ip:888,登录 phpMyAdmin,选择导入,并选择刚才下载下来的 create_tables.sql 文件,如图 9。

图 9 导入 create_tables.sql 文件

导入完成后的界面如图 10 所示,可以看出右侧多了一个叫做”phpmyadmin” 的数据库。

图 10 导入完成后的结果

打开 phpMyAdmin 下的配置文件 (/ 你的 phpMyAdmin 安装目录 /libraries/config.default.php),找到下列内容并修改:

/**
* Database used for Relation, Bookmark and PDF Features
* (see sql/create_tables.sql)
* - leave blank for no support
* SUGGESTED: 'phpmyadmin'
*
* @global string $cfg['Servers'][$i]['pmadb']
*/
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
/**
* Bookmark table
* - leave blank for no bookmark support
* SUGGESTED: 'pma__bookmark'
*
* @global string $cfg['Servers'][$i]['bookmarktable']
*/
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
/**
* table to describe the relation between links (see doc)
* - leave blank for no relation-links support
* SUGGESTED: 'pma__relation'
*
* @global string $cfg['Servers'][$i]['relation']
*/
$cfg['Servers'][$i]['relation'] = 'pma__relation';
/**
* table to describe the display fields
* - leave blank for no display fields support
* SUGGESTED: 'pma__table_info'
*
* @global string $cfg['Servers'][$i]['table_info']
*/
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
/**
* table to describe the tables position for the designer and PDF schema
* - leave blank for no PDF schema support
* SUGGESTED: 'pma__table_coords'
*
* @global string $cfg['Servers'][$i]['table_coords']
*/
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
/**
* table to describe pages of relationpdf
* - leave blank if you don't want to use this
* SUGGESTED: 'pma__pdf_pages'
*
* @global string $cfg['Servers'][$i]['pdf_pages']
*/
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
/**
* table to store column information
* - leave blank for no column comments/mime types
* SUGGESTED: 'pma__column_info'
*
* @global string $cfg['Servers'][$i]['column_info']
*/
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
/**
* table to store SQL history
* - leave blank for no SQL query history
* SUGGESTED: 'pma__history'
*
* @global string $cfg['Servers'][$i]['history']
*/
$cfg['Servers'][$i]['history'] = 'pma__history';
/**
* table to store recently used tables
* - leave blank for no "persistent" recently used tables
* SUGGESTED: 'pma__recent'
*/
$cfg['Servers'][$i]['recent'] = 'pma__recent';
/**
* table to store favorite tables
* - leave blank for no favorite tables
* SUGGESTED: 'pma__favorite'
*/
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
/**
* table to store UI preferences for tables
* - leave blank for no "persistent" UI preferences
* SUGGESTED: 'pma__table_uiprefs'
*/
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
/**
* table to store SQL tracking
* - leave blank for no SQL tracking
* SUGGESTED: 'pma__tracking'
*
* @global string $cfg['Servers'][$i]['tracking']
*/
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
/**
* table to store user preferences
* - leave blank to disable server storage
* SUGGESTED: 'pma__userconfig'
*
* @global string $cfg['Servers'][$i]['userconfig']
*/
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
/**
* table to store users and their assignment to user groups
* - leave blank to disable configurable menus feature
* SUGGESTED: 'pma__users'
*
* @global string $cfg['Servers'][$i]['users']
*/
$cfg['Servers'][$i]['users'] = 'pma__users';
/**
* table to store allowed menu items for each user group
* - leave blank to disable configurable menus feature
* SUGGESTED: 'pma__usergroups'
*
* @global string $cfg['Servers'][$i]['usergroups']
*/
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
/**
* table to store information about item hidden from navigation tree
* - leave blank to disable hide/show navigation items feature
* SUGGESTED: 'pma__navigationhiding'
*
* @global string $cfg['Servers'][$i]['navigationhiding']
*/
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
/**
* table to store information about saved searches from query-by-example on a db
* - leave blank to disable saved searches feature
* SUGGESTED: 'pma__savedsearches'
*
* @global string $cfg['Servers'][$i]['savedsearches']
*/
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
/**
* table to store central list of columns per database
* - leave blank to disable central list of columns feature
* SUGGESTED: 'pma__central_columns'
*
* @global string $cfg['Servers'][$i]['central_columns']
*/
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
/**
* table to store designer settings
* - leave blank to disable the storage of designer settings
* SUGGESTED: 'pma__designer_settings'
*
* @global string $cfg['Servers'][$i]['designer_settings']
*/
$cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
/**
* table to store export templates
* - leave blank to disable saved searches feature
* SUGGESTED: 'pma__export_templates'
*
* @global string $cfg['Servers'][$i]['export_templates']
*/
$cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';

关闭页面后再次打开,问题解决。

6. 配置 phpMyAdmin 使用 https 和域名访问。

想要使用域名和 https 来访问 phpMyAdmin,只需要将 Negix 的配置修改一下即可 。下面贴上一个示例配置,大家可以参照此进行修改:

server {
listen 888 ssl; # 如果你不想使用888这个端口访问phpMyAdmin,请将其改为其他端口,如12345
server_tokens off;
keepalive_timeout 5;
root /yourdirectory/phpmyadmin; # 这里写你的phpMyAdmin的根目录
index index.php index.html;
server_name www.yourdomain.com; # 这里写你的域名
ssl_certificate yourSSLcertificate.crt; # 这里写证书文件名称
ssl_certificate_key yourSSLcertificate.key; # 这里写私钥文件名称
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
}
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;
}
}

这样配置完成后,在浏览器中输入 https://www.yourdomain.com:888/ 就可以访问你的 phpMyAdmin 页面了。

本文采用知识共享 署名 - 非商业性使用 4.0 许可,转载请注明出处;如果有某些问题想和本人讨论,可以发送邮件至:absolutezero@stu.xjtu.edu.cn

评论

  1. h
    hecady
    Windows Chrome
    2022-11-1
    2022-11-02 1:08:10

    不建议对公网开放数据库功能

    • 博主
      hecady
      Windows Firefox
      2022-11-2
      2022-11-02 20:12:03

      好的,多谢提醒。我这篇文章中说的方法仅作教程用,实际并未开放。

发送评论 编辑评论

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇