PhpPgAdmin是用PHP编写的PostgreSQL管理界面。它允许您通过 Web 界面管理数据库并执行各种任务,例如创建表、管理用户和运行 SQL 查询。
在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 phpPgAdmin
第 1 步。首先,通过在终端中运行以下命令,确保所有系统软件包都是最新的。apt
<span class="pln">sudo apt update sudo apt upgrade</span>
第 2 步。安装 Apache HTTP 服务器。
默认情况下,Apache 在 Ubuntu 22.04 基础存储库上可用。现在运行以下命令,将最新版本的 Apache 安装到您的 Ubuntu 系统中:
<span class="pln">sudo apt install apache2</span>
成功安装后,启用 Apache(在系统启动时自动启动)、启动并使用以下命令验证状态:
<span class="pln">sudo systemctl enable apache2 sudo systemctl start apache2 sudo systemctl status apache2</span>
您可以使用以下命令确认 Apache2 版本:
<span class="pln">apache2 </span><span class="pun">-</span><span class="pln">v</span>
有关安装和管理 Apache 的其他资源,请阅读下面的帖子:
- 如何在 Ubuntu Linux √ 上安装 Apache。
第 3 步。安装 PHP。
默认情况下,PHP 在 Ubuntu 22.04 基本存储库中不可用。现在运行以下命令将Ondrej PPA添加到您的系统中:
<span class="pln">sudo </span><span class="kwd">add</span><span class="pun">-</span><span class="pln">apt</span><span class="pun">-</span><span class="pln">repository ppa</span><span class="pun">:</span><span class="pln">ondrej</span><span class="pun">/</span><span class="pln">php</span>
添加存储库后,更新 APT 索引,然后使用以下命令安装 PHP 8.2:
<span class="pln">sudo apt update sudo apt install php8</span><span class="pun">.</span><span class="lit">2</span><span class="pln"> php8</span><span class="pun">.</span><span class="lit">2</span><span class="pun">-</span><span class="pln">cli php8</span><span class="pun">.</span><span class="lit">2</span><span class="pun">-</span><span class="pln">common php8</span><span class="pun">.</span><span class="lit">2</span><span class="pun">-</span><span class="pln">imap php8</span><span class="pun">.</span><span class="lit">2</span><span class="pun">-</span><span class="pln">redis php8</span><span class="pun">.</span><span class="lit">2</span><span class="pun">-</span><span class="pln">snmp php8</span><span class="pun">.</span><span class="lit">2</span><span class="pun">-</span><span class="pln">xml php8</span><span class="pun">.</span><span class="lit">2</span><span class="pun">-</span><span class="pln">zip php8</span><span class="pun">.</span><span class="lit">2</span><span class="pun">-</span><span class="pln">mbstring php8</span><span class="pun">.</span><span class="lit">2</span><span class="pun">-</span><span class="pln">curl libapache2</span><span class="pun">-</span><span class="pln">mod</span><span class="pun">-</span><span class="pln">php php8</span><span class="pun">.</span><span class="lit">2</span><span class="pun">-</span><span class="pln">mysql</span>
确认安装并检查已安装的 PHP 构建版本:
<span class="pln">php </span><span class="pun">--</span><span class="pln">version</span>
输出:
<span class="pln">root@idroot</span><span class="pun">.</span><span class="pln">us</span><span class="pun">:~#</span><span class="pln"> php </span><span class="pun">-</span><span class="pln">v PHP </span><span class="lit">8.1</span><span class="pun">.</span><span class="lit">2</span><span class="pun">-</span><span class="lit">1ubuntu2.9</span> <span class="pun">(</span><span class="pln">cli</span><span class="pun">)</span> <span class="pun">(</span><span class="pln">built</span><span class="pun">:</span> <span class="typ">Dec</span> <span class="lit">16</span> <span class="lit">2022</span> <span class="lit">12</span><span class="pun">:</span><span class="lit">58</span><span class="pun">:</span><span class="lit">11</span><span class="pun">)</span> <span class="pun">(</span><span class="pln">NTS</span><span class="pun">)</span> <span class="typ">Copyright</span> <span class="pun">(</span><span class="pln">c</span><span class="pun">)</span> <span class="typ">The</span><span class="pln"> PHP </span><span class="typ">Group</span> <span class="typ">Zend</span> <span class="typ">Engine</span><span class="pln"> v4</span><span class="pun">.</span><span class="lit">1.2</span><span class="pun">,</span> <span class="typ">Copyright</span> <span class="pun">(</span><span class="pln">c</span><span class="pun">)</span> <span class="typ">Zend</span> <span class="typ">Technologies</span> <span class="kwd">with</span> <span class="typ">Zend</span> <span class="typ">OPcache</span><span class="pln"> v8</span><span class="pun">.</span><span class="lit">1.2</span><span class="pun">-</span><span class="lit">1ubuntu2.9</span><span class="pun">,</span> <span class="typ">Copyright</span> <span class="pun">(</span><span class="pln">c</span><span class="pun">),</span> <span class="kwd">by</span> <span class="typ">Zend</span> <span class="typ">Technologies</span>
第 4 步。安装 PostgreSQL。
默认情况下,PostgreSQL 在 Ubuntu 22.04 基础存储库上可用。现在运行以下命令将最新版本的PostgreSQL安装到您的系统中:
<span class="pln">sudo apt install postgresql postgresql</span><span class="pun">-</span><span class="pln">contrib</span>
成功安装后,启用 PostgreSQL(在系统启动时自动启动)、启动并使用以下命令验证状态:
<span class="pln">sudo systemctl enable postgresql sudo systemctl start postgresql sudo systemctl status postgresql</span>
有关安装 PostgreSQL 的其他资源,请阅读下面的帖子:
- 如何在 Ubuntu Linux 上安装 PostgreSQL√
第 4 步。在 Ubuntu 22.04 上安装 phpPgAdmin。
要安装 phpPgAdmin,请运行以下命令:
<span class="pln">sudo apt install phppgadmin php</span><span class="pun">-</span><span class="pln">pgsql</span>
接下来,使用我们最喜欢的编辑器打开 phpPgAdmin 配置文件,并进行一些更改,如下所示:/etc/phppgadmin/config.inc.php
<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><span class="pln"> $conf</span><span class="pun">[</span><span class="str">'owned_only'</span><span class="pun">]</span> <span class="pun">=</span> <span class="kwd">true</span><span class="pun">;</span>
第5步。配置 Apache 虚拟主机。
现在为 phpPgAdmin 创建虚拟主机配置文件:
<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"><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">phppgadmin</span><span class="tag">></span> <span class="tag"><IfModule</span> <span class="atn">mod_dir</span><span class="pln">.</span><span class="atn">c</span><span class="tag">></span><span class="pln"> DirectoryIndex index.php </span><span class="tag"></IfModule></span><span class="pln"> AllowOverride None # Only allow connections from localhost: #Require local </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"> php_flag magic_quotes_gpc Off php_flag track_vars On #php_value include_path . </span><span class="tag"></IfModule></span> <span class="tag"><IfModule</span><span class="pln"> !</span><span class="atn">mod_php</span><span class="pln">.</span><span class="atn">c</span><span class="tag">></span> <span class="tag"><IfModule</span> <span class="atn">mod_actions</span><span class="pln">.</span><span class="atn">c</span><span class="tag">></span> <span class="tag"><IfModule</span> <span class="atn">mod_cgi</span><span class="pln">.</span><span class="atn">c</span><span class="tag">></span><span class="pln"> AddType application/x-httpd-php .php Action application/x-httpd-php /cgi-bin/php </span><span class="tag"></IfModule></span> <span class="tag"><IfModule</span> <span class="atn">mod_cgid</span><span class="pln">.</span><span class="atn">c</span><span class="tag">></span><span class="pln"> AddType application/x-httpd-php .php Action application/x-httpd-php /cgi-bin/php </span><span class="tag"></IfModule></span> <span class="tag"></IfModule></span> <span class="tag"></IfModule></span> <span class="tag"></Directory></span>
现在,我们可以重新启动 Apache Web 服务器,以便进行更改:
<span class="pln">sudo a2enmod rewrite sudo a2ensite phppgadmin</span><span class="pun">.</span><span class="pln">conf sudo systemctl restart apache2</span><span class="pun">.</span><span class="pln">service</span>
第 6 步。配置防火墙。
现在我们使用Apache设置了一个简单防火墙(UFW),以允许在HTTP和HTTPS的默认Web端口上进行公共访问:
<span class="pln">sudo ufw allow </span><span class="typ">OpenSSH</span><span class="pln"> sudo ufw allow </span><span class="str">'Apache Full'</span><span class="pln"> sudo ufw enable</span>
步骤 7.访问 phpPgAdmin Web 界面。
成功安装后,现在打开您的 Web 浏览器并使用 URL 访问 phpPgAdmin Web UI。http://your-domain.com/phppgadmin
感谢您使用本教程在 Ubuntu 22.04 LTS Jammy Jellyfish 系统上为 PostgreSQL 安装 phpPgAdmin 基于 Web 的管理工具。有关其他帮助或有用信息,我们建议您查看 phpPgAdmin 网站。