Here is the step by step instructions on how to install phpPgAdmin on Centos 7. PostgreSQL is a great database and phpPgAdmin is a web-based administration tool for PostgreSQL. Probably most postgresql DBA's will use the command line or pgadmin3 but if you are like me, using postgresql in a vps webserver somewhere then phpPgAdmin is a great timesaver tool.
Install the required packages.
You need to have epel repository available on your server. If you do not have it then install it , Click here to take you to Fedora Project website on how to install EPEL repo and come back here when done.
In this section we are going to assume you are using the default http server and php packages that comes with CentOS 7. the command below will install phpPgAdmin including php and the webserver. If the default httpd and php are already installed then the command will simply skip them.
yum -y install phpPgAdmin php-pgsql httpd php
Allow Apache/PHP to be able to connect to database if using selinux .
If selinux is enabled then you need to set selinux to allow httpd to connect to your database via network sockets.
setsebool -P httpd_can_network_connect_db on setsebool -P httpd_can_network_connect on
Configure phpPgAdmin to connect to your local postgresql database
Edit /etc/phpPgAdmin/config.inc.php file, we have to modify the admin file to enable the browser access.
Add the localhost in the following server parameter.
$conf['servers']['host'] = 'localhost';
If extra login security is true, then logins via phpPgAdmin with no password or certain usernames (pgsql, postgres, root, administrator) will be denied. To enable the postgres login, change it to false.
$conf['extra_login_security'] = false;
To simply hide other databases in the list make following condition to true – this does not in any way prevent your users from seeing other database by other means.
$conf['owned_only'] = true;
phpPgAdmin connects to the local postgresql server via network. We have to configure our postgresql server to accept local connections via md5 authentication.
Please enter the value as per your requirements inIPv4 and Ipv6 connections and make sure it accepts md5 passwords.
# IPv4 local connections: host all all 127.0.0.1/32 md5 host all all 192.168.2.0/24 md5 # IPv6 local connections: host all all ::1/128 md5
By-default phpPgAdmin places the web config file in /etc/httpd/conf.d directory; it has the rules and access permission for the web access. In CentOS 7, web access is managed by mod_authz_core.c module; so normal allow or deny rules wont work even if you modify.
Default config will look like below.
Alias /phpPgAdmin /usr/share/phpPgAdmin <Location /phpPgAdmin> <IfModule mod_authz_core.c> # Apache 2.4 Require local #Require host example.com </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order deny,allow Deny from all Allow from 127.0.0.1 Allow from ::1 # Allow from .example.com </IfModule> </Location>
Please comment Require local and add Require all granted just below to commented line, it will look like below.
Alias /phpPgAdmin /usr/share/phpPgAdmin
<Location /phpPgAdmin> <IfModule mod_authz_core.c> # Apache 2.4 # Require local Require all granted #Require host example.com </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order deny,allow Deny from all Allow from 127.0.0.1 Allow from ::1 # Allow from .example.com </IfModule> </Location>
Restart the services.
systemctl restart postgresql-9.3.service systemctl restart httpd.service
Congratulations you have installed phpPgAdmin
You can now browse to your server IP via a browser and you should get the following page: