phpMyAdmin是通过用户友好的Web界面管理MySQL或MariaDB数据库的重要工具。为了确保您的系统安全高效,安装最新版本的phpMyAdmin至关重要。
在 Debian 12 Bookworm 上安装 phpMyAdmin
第 1 步。在我们安装任何软件之前,通过在终端中运行以下命令来确保您的系统是最新的非常重要:apt
<span class="pln">sudo apt update sudo apt upgrade</span>
此命令更新软件包列表并将已安装的软件包升级到最新版本。
第 2 步。安装 LAMP 堆栈。
要运行phpMyAdmin,你需要一个Web服务器,一个数据库服务器和PHP。安装 LAMP 堆栈组件:
<span class="pln">sudo apt install apache2 mysql</span><span class="pun">-</span><span class="pln">server php libapache2</span><span class="pun">-</span><span class="pln">mod</span><span class="pun">-</span><span class="pln">php</span>
此命令安装 Apache、MySQL(或 MariaDB)和 PHP,构成了 phpMyAdmin 的基础。
第 3 步。在 Debian 12 上安装 phpMyAdmin。
现在,让我们使用以下命令安装 phpMyAdmin:
<span class="pln">sudo apt install phpmyadmin</span>
在安装过程中,系统将提示您选择要自动配置的 Web 服务器。选择 Apache 并继续。
第 4 步。配置 Apache 以与 phpMyAdmin 一起工作
在 Apache 配置目录中创建一个指向 phpMyAdmin 配置文件的符号链接:
<span class="pln">sudo ln </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">phpmyadmin</span><span class="pun">/</span><span class="pln">apache</span><span class="pun">.</span><span class="pln">conf </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">-</span><span class="pln">available</span><span class="pun">/</span><span class="pln">phpmyadmin</span><span class="pun">.</span><span class="pln">conf</span>
为 Apache 启用 phpMyAdmin 配置:
<span class="pln">sudo a2enconf phpmyadmin</span>
为了增强安全性,我们将向phpMyAdmin添加一个密码:
<span class="pln">sudo htpasswd </span><span class="pun">-</span><span class="pln">c </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">phpmyadmin</span><span class="pun">/.</span><span class="pln">htpasswd your_username</span>
编辑 phpMyAdmin Apache 配置文件:
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">-</span><span class="pln">available</span><span class="pun">/</span><span class="pln">phpmyadmin</span><span class="pun">.</span><span class="pln">conf</span>
在部分内添加以下行:<Directory /usr/share/phpmyadmin>
<span class="tag"><Directory</span> <span class="pun">/</span><span class="atn">usr</span><span class="pun">/</span><span class="atn">share</span><span class="pun">/</span><span class="atn">phpmyadmin</span><span class="tag">></span><span class="pln"> Options SymLinksIfOwnerMatch DirectoryIndex index.php </span><span class="tag"><IfModule</span> <span class="atn">mod_php</span><span class="pln">.</span><span class="atn">c</span><span class="tag">></span><span class="pln"> AddType application/x-httpd-php .php php_flag magic_quotes_gpc Off php_flag track_vars On php_flag register_globals Off php_admin_flag allow_url_fopen Off php_value include_path . php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext </span><span class="tag"></IfModule></span> <span class="tag"></Directory></span>
启用 phpMyAdmin 所需的 PHP 扩展:
<span class="pln">sudo phpenmod mbstring sudo phpenmod zip sudo systemctl restart apache2</span>
重新启动 Apache Web 服务器以应用更改:
<span class="pln">sudo systemctl restart apache2</span>
验证防火墙是否处于活动状态,并具有已配置的规则:
<span class="pln">sudo ufw status</span>
第5步。配置防火墙。
如果你有一个与phpMyAdmin一起运行的Web服务器(Apache,Nginx),你应该允许HTTP(端口80)和HTTPS(端口443)流量:
<span class="pln">sudo ufw allow </span><span class="typ">OpenSSH</span><span class="pln"> sudo ufw allow </span><span class="lit">80</span><span class="pun">/</span><span class="pln">tcp sudo ufw allow </span><span class="lit">443</span><span class="pun">/</span><span class="pln">tcp</span>
配置规则后,启用 UFW:
<span class="pln">sudo ufw enable</span>
第 6 步。访问 phpMyAdmin Web UI。
您现在可以通过打开Web浏览器并输入以下URL来访问phpMyAdmin:
<span class="pln">http</span><span class="pun">:</span><span class="com">//your_server_ip/phpmyadmin</span>
步骤 7.将 phpMyAdmin 更新到最新版本。
保持phpMyAdmin最新状态对于安全性和性能至关重要。现在访问 phpMyAdmin 网站以检查最新版本。
使用以下命令将最新的 phpMyAdmin 版本下载到您的服务器。请务必将“版本”替换为实际版本号:wget
<span class="pln">wget https</span><span class="pun">:</span><span class="com">//files.phpmyadmin.net/phpMyAdmin/version/phpMyAdmin-version-all-languages.tar.gz</span>
解压缩下载的存档并将其内容复制到 phpMyAdmin 目录:
<span class="pln">tar xzf phpMyAdmin</span><span class="pun">-</span><span class="pln">version</span><span class="pun">-</span><span class="pln">all</span><span class="pun">-</span><span class="pln">languages</span><span class="pun">.</span><span class="pln">tar</span><span class="pun">.</span><span class="pln">gz sudo cp </span><span class="pun">-</span><span class="pln">r phpMyAdmin</span><span class="pun">-</span><span class="pln">version</span><span class="pun">-</span><span class="pln">all</span><span class="pun">-</span><span class="pln">languages</span><span class="com">/* /usr/share/phpmyadmin/</span>
更新符号链接以指向最新版本:
<span class="pln">sudo ln </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">share</span><span class="pun">/</span><span class="pln">phpmyadmin </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">phpmyadmin</span>
有关更详细的调试和日志分析,请查看 Apache 的错误日志:
<span class="pln">sudo tail </span><span class="pun">-</span><span class="pln">f </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">/</span><span class="pln">error</span><span class="pun">.</span><span class="pln">log</span>
感謝您使用這本教鬆在 Debian 12 Bookworm 上安裝最新版本的 phpMyAdmin。有关其他帮助或有用信息,我们建议您查看 phpMyAdmin 官方网站。