phpPgAdmin 是一個基於網絡的工具,可幫助使用 PHP 前端管理 PostgreSQL 資料庫。
安裝
PhpPgAdmin 需要一個帶 PHP 的網絡伺服器,如 Apache。要設置它,請參閱Apache HTTP 伺服器和Apache HTTP 伺服器#PHP。
安裝 phppgadminAUR 軟體包。
配置
PHP
您需要編輯 /etc/php/php.ini
,取消注釋以下一行,以啟用 PHP 中的 pgsql
擴展:
extension=pgsql
您需要確保 PHP 可以訪問 /etc/webapps
。如有必要,請將其添加到 /etc/php/php.ini
中的 open_basedir
:
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps
網絡伺服器
Apache
創建 Apache 配置文件:
/etc/httpd/conf/extra/phppgadmin.conf
Alias /phppgadmin "/usr/share/webapps/phppgadmin" <Directory "/usr/share/webapps/phppgadmin"> DirectoryIndex index.php AllowOverride All Options FollowSymlinks Require all granted # phppgadmin raises deprecated warnings that lead # to parsing errors in JS #php_flag display_startup_errors off #php_flag display_errors off #php_flag html_errors off </Directory>
並將其包含在 /etc/httpd/conf/httpd.conf
中:
# phpPgAdmin configuration Include conf/extra/phppgadmin.conf
您還需要連接 php7:
Include conf/extra/php7_module.conf LoadModule php7_module modules/libphp7.so
默認情況下,每個人都能看到 phpPgAdmin 頁面,若要更改,請編輯 /etc/httpd/conf/extra/phppgadmin.conf
以滿足您的需求。例如,如果只希望在同一台機器上訪問,請將 Require all granted
替換為 Require local
。
Lighttpd
lighttpd 的 php 設置與 apache 完全相同。 在 lighttpd 配置中為 phppgadmin 設置一個別名。
alias.url = ( "/phppgadmin" => "/usr/share/webapps/phppgadmin/")
然後在配置(server.modules 部分)中啟用 mod_alias、mod_fastcgi 和 mod_cgi。
確保 lighttpd 已設置為服務 php 文件,Lighttpd#FastCGI。
重啟 lighttpd 並瀏覽 http://localhost/phppgadmin/index.php 。
nginx
請確保按照 nginx#nginx 配置中的說明,為 PHP 設置 nginx#FastCGI 和單獨的配置文件。
使用此方法,您將以 phppgadmin.<domain>
的身份訪問 PhpPgAdmin。
您可以使用伺服器塊設置子域(或域),如
server { server_name phppgadmin.<domain.tld>; root /usr/share/webapps/phppgadmin; index index.php; include php.conf; }
phpPgAdmin 配置
phpPgAdmin 的配置文件位於 /etc/webapps/phppgadmin/config.inc.php
。
如果 PostgreSQL 伺服器位於 localhost
,則可能需要編輯以下一行:
$conf['servers'][0]['host'] = ;
到:
$conf['servers'][0]['host'] = 'localhost';
訪問 phpPgAdmin 安裝
phpPgAdmin 安裝完成。在開始使用之前,您需要通過重啟 httpd.service
以重啟 apache 伺服器。
您可以通過 http://localhost/phppgadmin/ 訪問 phpPgAdmin 安裝。
問題解決
由於安全原因,登錄被禁止
如果 extra_login_security 設置為 "true",那麼通過 phpPgAdmin 進行的無密碼登錄或特定用戶名(psql、postgres、root、administrator)登錄將被拒絕。只有在閱讀了常見問題並了解如何修改 PostgreSQL 的 pg_hba.conf
以啟用帶密碼的本地連接之後,才能將此設置為 false
。
編輯 /etc/webapps/phppgadmin/config.inc.php
並更改以下行:
$conf['extra_login_security'] = true;
到:
$conf['extra_login_security'] = false;
然後重啟 postgresql.service
。
虛擬類 -- 無法實例化
此錯誤可能是已廢棄的警告。Issue。
編輯 /usr/share/webapps/phppgadmin/libraries/adodb/adodb.inc.php
並更改以下行:
/** * Constructor */ function __construct() { die('Virtual Class -- cannot instantiate'); }
到:
/** * Constructor */ function __construct() { // die('Virtual Class -- cannot instantiate'); }