在关系数据库的世界里,PostgreSQL作为一个强大的开源选择而站得住脚。它用途广泛,坚固耐用,广泛用于各种应用。为了有效地管理您的 PostgreSQL 数据库,您需要一个可靠且用户友好的工具。这就是phpPgAdmin发挥作用的地方。它是一个基于Web的管理工具,简化了处理PostgreSQL数据库的任务。
在 Debian 12 上安装 phpPgAdmin
第 1 步。在我们安装任何软件之前,通过在终端中运行以下命令来确保您的系统是最新的非常重要:apt
<span class="pln">sudo apt update sudo apt upgrade</span>
此命令将刷新存储库,允许您安装最新版本的软件包。
第 2 步。安装所需的依赖项。
phpPgAdmin 依赖于几个依赖项才能正常运行。我们需要安装这些依赖项,包括 Apache Web 服务器、PHP 和 PostgreSQL PHP 扩展。运行以下命令:
<span class="pln">sudo apt install apache2 php postgresql php</span><span class="pun">-</span><span class="pln">pgsql</span>
第 3 步。在 Debian 12 上安装 phpPgAdmin。
现在我们已经安装了依赖项,是时候获取phpPgAdmin了。我们将从官方网站下载最新版本并提取。执行以下命令:
<span class="pln">wget https</span><span class="pun">:</span><span class="com">//github.com/phppgadmin/phppgadmin/releases/download/REL_7-13-0/phpPgAdmin-7.13.0.tar.gz</span>
<span class="pln">tar xvf phpPgAdmin</span><span class="pun">-</span><span class="lit">7.13</span><span class="pun">.</span><span class="lit">0.tar</span><span class="pun">.</span><span class="pln">gz</span>
下载 phpPgAdmin 后,我们将导航到 phpPgAdmin 目录并创建一个配置文件。执行以下命令:
<span class="pln">sudo cp </span><span class="pun">-</span><span class="pln">r phpPgAdmin</span><span class="pun">-</span><span class="lit">7.13</span><span class="pun">.</span><span class="lit">0</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">phppgadmin sudo mv </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">phppgadmin</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">/</span><span class="pln">config</span><span class="pun">.</span><span class="pln">inc</span><span class="pun">.</span><span class="pln">php</span><span class="pun">-</span><span class="pln">dist </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">phppgadmin</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">/</span><span class="pln">config</span><span class="pun">.</span><span class="pln">inc</span><span class="pun">.</span><span class="pln">php</span>
第 4 步。配置 Apache Web Server。
现在,我们需要配置 Apache 来为 phpPgAdmin 提供服务。使用您喜欢的文本编辑器为 phpPgAdmin 创建一个虚拟主机配置文件(我们将使用 Nano):
<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">sites</span><span class="pun">-</span><span class="pln">available</span><span class="pun">/</span><span class="pln">phppgadmin</span><span class="pun">.</span><span class="pln">conf</span>
并添加以下配置:
<span class="tag"><VirtualHost</span><span class="pln"> *:80</span><span class="tag">></span><span class="pln"> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/phppgadmin </span><span class="tag"><Directory</span> <span class="pun">/</span><span class="atn">var</span><span class="pun">/</span><span class="atn">www</span><span class="pun">/</span><span class="atn">html</span><span class="pun">/</span><span class="atn">phppgadmin</span><span class="tag">></span><span class="pln"> Options FollowSymLinks AllowOverride None Require all granted </span><span class="tag"></Directory></span><span class="pln"> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </span><span class="tag"></VirtualHost></span>
保存文件并退出文本编辑器。要启用新的虚拟主机,请运行:
<span class="pln">sudo a2ensite phppgadmin</span><span class="pun">.</span><span class="pln">conf</span>
为了使 phpPgAdmin 可以通过 Web 访问,我们需要启用必要的 Apache 模块并重新启动 Web 服务器。执行以下命令:
<span class="pln">sudo a2enmod rewrite sudo systemctl restart apache2</span>
在处理phpPgAdmin等数据库管理工具时,安全性至关重要。我们建议设置身份验证和访问控制:
<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">apache2</span><span class="pun">/.</span><span class="pln">htpasswd your_username</span>
接下来,编辑 phpPgAdmin 配置文件:
<span class="pln">sudo nano </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">phppgadmin</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">/</span><span class="pln">config</span><span class="pun">.</span><span class="pln">inc</span><span class="pun">.</span><span class="pln">php</span>
找到以下行:
<span class="pln">$conf</span><span class="pun">[</span><span class="str">'extra_login_security'</span><span class="pun">]</span> <span class="pun">=</span> <span class="kwd">false</span><span class="pun">;</span>
并将其更改为:
<span class="pln">$conf</span><span class="pun">[</span><span class="str">'extra_login_security'</span><span class="pun">]</span> <span class="pun">=</span> <span class="kwd">true</span><span class="pun">;</span>
保存文件并退出文本编辑器。重新启动 Apache 以应用更改:
<span class="pln">sudo systemctl restart apache2</span>
第5步。访问 phpPgAdmin Web UI。
完成所有设置后,您现在可以通过Web浏览器访问phpPgAdmin。打开浏览器并输入以下 URL:
<span class="pln">http</span><span class="pun">:</span><span class="com">//your_server_ip/phppgadmin</span>
系统将提示您输入之前设置的用户名和密码。登录后,您将可以通过phpPgAdmin的用户友好界面完全访问PostgreSQL数据库。
感谢您使用本教程在 Debian 12 Bookworm 上安装最新版本的 phpPgAdmin。有关其他帮助或有用信息,我们建议您查看 phpPgAdmin 官方网站。