(Last Updated On: November 13, 2018)

pgAdmin is the leading Open Source feature-rich PostgreSQL administration and development platform that runs on Linux, Unix, Mac OS X, and Windows. pgAdmin can be used to manage PostgreSQL 9.2 and above. With the release of pgAdmin 4, there was migration from Bootstrap 3 to Bootstrap 4.

pgAdmin4 on CentOS 7 / Fedora 29 / Fedora 28 Requirements

You need to have PostgreSQL installed on your system before you can install pgAdmin 4. Below are the guides to help you install PostgreSQL:

How to install PostgreSQL 11 on CentOS 7

How to install PostgreSQL 11 on Fedora 29 / Fedora 28

If you’re not SELinux expert, set it to run in Permissive Mode

sudo setenforce 0
sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

Install pgAdmin 4 on CentOS 7

After installing PostgreSQL, you can begin the installation of pgAdmin 4 on CentOS 7. You need to add PostgreSQL RPM repository, which should have been done while installing PostgreSQL.

sudo yum -y install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

Update your system packages then install the pgAdmin package:

sudo yum -y update
sudo yum -y install pgadmin4

Install pgAdmin Fedora 29 / Fedora 28

Add PostgreSQL Yum Repository to your Fedora system by running the below command:

For Fedora 29 use:

sudo dnf -y install https://download.postgresql.org/pub/repos/yum/11/fedora/fedora-29-x86_64/pgdg-fedora11-11-2.noarch.rpm

For Fedora 28 use:

sudo dnf -y install https://download.postgresql.org/pub/repos/yum/11/fedora/fedora-28-x86_64/pgdg-fedora11-11-2.noarch.rpm

Once the repositories have been added, update system packages then install pgadmin4

sudo yum -y update
sudo yum -y install pgadmin4

Among the dependencies installed is pgadmin4-web and httpd web server.

Configure pgAdmin 4 on CentOS 7 / Fedora 29 / Fedora 28

Now that we have pgAdmin 4 installed, let’s configure it.

1. Start and enable httpd service to start on boot

sudo systemctl start httpd && sudo systemctl enable httpd

You can confirm service status by running:

sudo systemctl status httpd

2. Rename pgAdmin Apache configuration sample

sudo mv /etc/httpd/conf.d/pgadmin4.conf.sample /etc/httpd/conf.d/pgadmin4.conf

3. Edit the file to add VirtualHost section, it should look like below:

<VirtualHost *:80>
ServerName pgadmin.example.com
LoadModule wsgi_module modules/mod_wsgi.so
WSGIDaemonProcess pgadmin processes=1 threads=25
WSGIScriptAlias /pgadmin4 /usr/lib/python2.7/site-packages/pgadmin4-web/pgAdmin4.wsgi

<Directory /usr/lib/python2.7/site-packages/pgadmin4-web/>
	WSGIProcessGroup pgadmin
	WSGIApplicationGroup %{GLOBAL}
	<IfModule mod_authz_core.c>
		# Apache 2.4
		Require all granted
	</IfModule>
	<IfModule !mod_authz_core.c>
		# Apache 2.2
		Order Deny,Allow
		Deny from All
		Allow from 127.0.0.1
		Allow from ::1
	</IfModule>
</Directory>
</VirtualHost>

Confirm configuration syntax to prevent any errors and restart httpd service.

$ sudo httpd -t
Syntax OK
$ sudo systemctl restart httpd

4. Create pgAdmin data directories:

sudo mkdir -p /var/lib/pgadmin4/
sudo mkdir -p /var/log/pgadmin4/

5. Edit config_local.py and add the following settings. In most cases, the default file locations should be appropriate:

sudo vi /usr/lib/python2.7/site-packages/pgadmin4-web/config_distro.py

Add:

LOG_FILE = '/var/log/pgadmin4/pgadmin4.log'
SQLITE_PATH = '/var/lib/pgadmin4/pgadmin4.db'
SESSION_DB_PATH = '/var/lib/pgadmin4/sessions'
STORAGE_DIR = '/var/lib/pgadmin4/storage'

6. Run the following command to create the configuration database:

python /usr/lib/python2.7/site-packages/pgadmin4-web/setup.py

This will ask you to Enter the email address and the password to use for the initial pgAdmin user account.

Email address: [email protected]
Password: <INPUT PASSWORD>
Retype password:<Confirm PASSWORD>
pgAdmin 4 - Application Initialisation
======================================

Set permissions for pgAdmin directories to apache user

sudo chown -R apache:apache /var/lib/pgadmin4
sudo chown -R apache:apache /var/log/pgadmin4

Access pgAdmin 4 Web Interface

if you have an active firewall service, allow http port

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload

Open http://pgadmin.example.com/pgadmin4 to log in to the pgAdmin with the credentials created step 6 above.

On the first page of pgAdmin, add a PostgreSQL server to administer with pgAdmin by clicking on “Add New Server”. This can be local or a remote PostgreSQL server.

Under the “General” section, give the server a name & description.

Under “Connection” tab, provide access details – DB host, DB user and Password.

When done, Click Save button to save the configurations. If you were successful adding the server, the name will appear in the left sidebar. Select the server to see database summary information and make changes.

I hope our article was helpful in installing pgAdmin 4 on CentOS 7 / Fedora 29 & Fedora 28 server/Desktop.