phpMyAdmin 是一个免费的、开源的、基于 Web 的应用程序,用于管理 MySQL 数据库、用户帐户和特权、执行 SQL 语句、以各种数据格式导入和导出数据,以及从 Web 界面执行更多操作。
在 Debian 11 Bullseye 上使用 Nginx 安装 phpMyAdmin
步骤 1. 在我们安装任何软件之前,通过apt
在终端中运行以下命令来确保您的系统是最新的很重要:
sudo apt update sudo apt upgrade
步骤 2. 安装 LEMP 堆栈。
如果您的服务器上尚未安装 LEMP(Linux + Nginx+ MySQL/MariDB+ PHP),您可以按照我们的教程进行操作。
步骤 3. 配置 MySQL。
现在我们为 phpMyAdmin 创建一个新的超级用户帐户:
sudo mysql -u root -p
这将提示您输入密码,因此请输入您的 MariaDB 根密码并按 Enter。登录到数据库服务器后,您需要为 phpMyAdmin 安装创建一个数据库:
MariaDB> CREATE DATABASE app_db; MariaDB> CREATE USER \'app_user\'@\'localhost\' IDENTIFIED BY \'your-strong-password\'; MariaDB> GRANT ALL PRIVILEGES ON app_db.* TO \'app_user\'@\'localhost\' WITH GRANT OPTION; MariaDB> FLUSH PRIVILEGES; MariaDB> EXIT;
第 4 步。 在 Debian 11 上安装 phpMyAdmin。
默认情况下,Debian 11 Bullseye 存储库中不提供 phpMyAdmin,因此您需要从官方页面手动下载 phpMyAdmin:
wget https://files.phpmyadmin.net/phpMyAdmin/5.1.1/phpMyAdmin-5.1.1-all-languages.tar.gz
接下来,将 phpMyAdmin 存档解压缩到您的 Web 服务器根目录:
tar xvf phpMyAdmin-5.1.1-all-languages.tar.gz sudo mv phpMyAdmin-5.1.1-all-languages /usr/share/phpMyAdmin
步骤 5. 配置 phpMyAdmin。
现在我们复制示例 phpMyAdmin 配置文件并重命名如下:
sudo cp -pr /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php
接下来,编辑配置文件:
sudo nano /usr/share/phpMyAdmin/config.inc.php
生成一个河豚秘密并更新配置文件中的秘密:
$cfg[\'blowfish_secret\'] = \'eDjtEzAk8N3Rk}AFY.vBW}UtYL7VPbGo\'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
另外,取消注释 phpMyAdmin 存储设置:
/** * phpMyAdmin configuration storage settings. */ /* User used to manipulate with storage */ $cfg[\'Servers\'][$i][\'controlhost\'] = \'localhost\'; // $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\';
步骤 6. 为 phpMyAdmin 配置数据库和用户。
现在我们通过运行以下命令来创建配置存储数据库和表:
sudo mysql < /usr/share/phpMyAdmin/sql/create_tables.sql -u root -p
接下来,使用以下命令连接到 MariaDB shell:
sudo mysql -u root -p
连接后,将所有必要的权限授予 phpMyAdmin 数据库:
CREATE USER \'pma\'@\'localhost\' IDENTIFIED BY \'pmapass\'; GRANT ALL PRIVILEGES ON phpmyadmin.* TO \'pma\'@\'localhost\' WITH GRANT OPTION; FLUSH PRIVILEGES; EXIT;
步骤 7. 为 phpMyAdmin 配置 Nginx。
现在我们为 phpMyAdmin 创建一个 Nginx 虚拟主机配置文件:
sudo nano /etc/nginx/conf.d/phpMyAdmin.conf
添加以下文件:
server { listen 80; server_name pma.your-domain.com; root /usr/share/phpMyAdmin; location / { index index.php; } ## Images and static content is treated different location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ { access_log off; expires 30d; } location ~ /\\.ht { deny all; } location ~ /(libraries|setup/frames|setup/libs) { deny all; return 404; } location ~ \\.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin$fastcgi_script_name; } }
保存并关闭,然后tmp
为 phpMyAdmin创建一个目录,然后更改权限:
sudo mkdir /usr/share/phpMyAdmin/tmp sudo chmod 777 /usr/share/phpMyAdmin/tmp
接下来,为 phpMyAdmin 目录设置正确的所有权:
sudo chown -R www-data:www-data /usr/share/phpMyAdmin
最后,重启 Nginx 和 PHP-fpm 服务:
sudo systemctl restart nginx sudo systemctl restart php7.4-fpm
步骤 8. 访问 phpMyAdmin Web 界面。
安装成功后,打开浏览器浏览,phpMyAdmin 会询问您安装 MySQL 的用户名和密码,您可以使用 root 作为用户和 root MySQL 密码。http://your-domain.com/
感谢您使用本教程在 Debian 11 Bullseye 上使用 Nginx 安装最新版本的 phpMyAdmin。如需更多帮助或有用信息,我们建议您查看官方 phpMyAdmin 网站。