How to Install pgAdmin 4 on RHEL 7

pgAdmin 4 is the leading open-source administration and management tool for PostgreSQL databases. It provides a feature-rich web-based interface for browsing database objects, running SQL queries, monitoring server activity, managing roles and tablespaces, and much more. Unlike pgAdmin 3 which was a native desktop application, pgAdmin 4 runs as a Python web application (Flask/SQLAlchemy) that can be deployed either as a local desktop application or as a shared web service behind Apache. On RHEL 7, the recommended installation method is via the official PostgreSQL Global Development Group (PGDG) yum repository, which packages pgAdmin 4 as RPMs including a pre-configured Apache virtual host definition. This tutorial walks through the full installation and initial configuration process.

Prerequisites

  • RHEL 7 server with root or sudo access
  • PostgreSQL 9.6 or later installed and running (the database server pgAdmin will manage)
  • Apache HTTP Server (httpd) installed
  • Python 3.6+ available (provided by the PGDG packages)
  • mod_wsgi for Apache (provided as part of the pgAdmin package dependencies)
  • Active RHEL subscription or EPEL/PGDG repo access
  • Firewall port 80 open (or port 443 for HTTPS)

Step 1: Install the PostgreSQL PGDG Repository

pgAdmin 4 is distributed via the official PGDG yum repository at yum.postgresql.org. Install the repository RPM for RHEL 7. The following example uses the repository for PostgreSQL 14 (which also provides pgAdmin 4):

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Verify the repository is present:

yum repolist | grep pgdg

You should see several pgdg repository entries listed.

Step 2: Install pgAdmin 4

There are two pgAdmin 4 packages available in the PGDG repository:

  • pgadmin4 — meta-package that installs both desktop and web modes
  • pgadmin4-web — web server mode only (recommended for headless servers)
  • pgadmin4-desktop — Electron-based desktop application

For a headless RHEL 7 server, install the web mode package:

sudo yum install -y pgadmin4-web

This pulls in all required dependencies: Python 3, Flask, SQLAlchemy, and mod_wsgi for Apache. The installation creates:

  • The pgAdmin 4 application at /usr/lib/python3.6/site-packages/pgadmin4/ (path may vary by Python version)
  • An Apache configuration file at /etc/httpd/conf.d/pgadmin4.conf
  • A setup script at /usr/pgadmin4/bin/setup-web.sh

Step 3: Run the Web Setup Script

The PGDG packaging provides a convenient setup script that creates the pgAdmin data directory, sets correct file ownership, and prompts you for the initial administrator account email and password. Run it as root:

sudo /usr/pgadmin4/bin/setup-web.sh

The script will prompt for:

  • Email address — this becomes the pgAdmin login username (e.g. [email protected])
  • Password — the pgAdmin web interface password

Sample interaction:

Setting up pgAdmin 4 in web mode on a Redhat based platform...
Creating configuration database...
NOTE: Configuring authentication for SERVER mode.

Enter the email address and password to use for the initial pgAdmin user account:

Email address: [email protected]
Password: 
Retype password:
pgAdmin 4 - Application Initialisation
======================================

Creating storage and log directories...
Configuring SELinux...
The apache service is already running.
You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4

The script also sets the correct SELinux file contexts on the pgAdmin data directory automatically.

Step 4: Review the Apache Configuration

The installed Apache configuration file at /etc/httpd/conf.d/pgadmin4.conf sets up a WSGI application at the /pgadmin4 URL path. Review and optionally restrict access:

sudo cat /etc/httpd/conf.d/pgadmin4.conf

A typical generated configuration looks like:

LoadModule wsgi_module modules/mod_wsgi.so

WSGIDaemonProcess pgadmin processes=1 threads=25 python-home=/usr/pgadmin4/venv
WSGIScriptAlias /pgadmin4 /usr/pgadmin4/web/pgAdmin4.wsgi

<Directory /usr/pgadmin4/web/>
    WSGIProcessGroup pgadmin
    WSGIApplicationGroup %{GLOBAL}

    <IfModule mod_authz_core.c>
        # Restrict to localhost and your management workstation
        Require ip 127.0.0.1
        Require ip ::1
        Require ip 192.168.1.0/24
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
        Allow from 192.168.1.0/24
    </IfModule>
</Directory>

Adjust the Require ip directives to match your management network. For production deployments, serve pgAdmin 4 exclusively over HTTPS rather than plain HTTP by creating a corresponding SSL virtual host.

Step 5: Configure SELinux

The setup script handles basic SELinux contexts, but Apache also needs permission to connect back to PostgreSQL over the network. Set the necessary SELinux booleans:

# Allow Apache (WSGI) to connect to PostgreSQL
sudo setsebool -P httpd_can_network_connect_db 1

# Allow Apache to connect to the network generally (if PostgreSQL is on a remote host)
sudo setsebool -P httpd_can_network_connect 1

# Verify
getsebool httpd_can_network_connect_db
getsebool httpd_can_network_connect

Also ensure the pgAdmin data and log directories have the correct SELinux type:

sudo restorecon -Rv /var/lib/pgadmin/
sudo restorecon -Rv /var/log/pgadmin/

Step 6: Start and Enable Apache

Restart Apache to load the pgAdmin WSGI configuration, then enable it to start at boot:

sudo systemctl restart httpd
sudo systemctl enable httpd
sudo systemctl status httpd

If the restart fails, check for configuration errors:

sudo apachectl configtest

Common issues include the mod_wsgi module not being installed or using the wrong Python version. Verify the module is available:

ls /etc/httpd/modules/mod_wsgi*.so

Step 7: Open the Firewall

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

Step 8: Access pgAdmin 4 and Complete the Setup Wizard

Open a browser on an allowed IP and navigate to:

http://<server-ip>/pgadmin4

You will see the pgAdmin 4 login page. Enter the email address and password you set during the setup-web.sh step. After logging in, pgAdmin 4 displays an empty dashboard with the browser panel on the left — there are no servers registered yet.

Step 9: Add a PostgreSQL Server Connection

In the left panel, right-click ServersRegisterServer. Fill in the connection details:

  • General tab
    • Name: My PostgreSQL Server (any label you choose)
  • Connection tab
    • Host name/address: 127.0.0.1 or the PostgreSQL server IP
    • Port: 5432
    • Maintenance database: postgres
    • Username: postgres (or your DBA account)
    • Password: your PostgreSQL user password
    • Save password: check if desired

Click Save. If the connection succeeds, the server appears in the left panel tree and you can expand it to see databases, schemas, tables, and all other PostgreSQL objects.

If the connection fails with “could not connect to server”, verify PostgreSQL is configured to accept connections from the pgAdmin server. Check /var/lib/pgsql/data/pg_hba.conf and postgresql.conf:

# In postgresql.conf — ensure PostgreSQL is listening
listen_addresses = 'localhost'   # or '*' for all interfaces

# In pg_hba.conf — allow the pgAdmin connection
# TYPE  DATABASE  USER      ADDRESS         METHOD
host    all       postgres  127.0.0.1/32    md5

After any changes to these files, reload PostgreSQL:

sudo systemctl reload postgresql

Step 10: Verify pgAdmin 4 is Fully Functional

With the server registered, test key functionality:

  1. Expand the server → Databases to see all databases
  2. Right-click a database → Query Tool, and run: SELECT version();
  3. Browse to a table and click View/Edit Data to verify data is visible
  4. Check DashboardServer Activity to see active connections and locks

pgAdmin 4 on RHEL 7 is straightforward to install via the PGDG yum repository, and the included setup-web.sh script handles most of the configuration complexity around file permissions and SELinux contexts. The combination of mod_wsgi, IP-based access restriction in Apache, and PostgreSQL’s pg_hba.conf provides a multi-layered security posture for the admin interface. For any production deployment, take the additional step of enabling HTTPS using a valid certificate — either from a public certificate authority or Let’s Encrypt — before exposing pgAdmin 4 beyond a local network.