How to Install pgAdmin4 on Ubuntu 24.04 Using Gunicorn and Nginx
19 Mar, 2026
Introduction
pgAdmin4 is a powerful, open-source administration and development platform for PostgreSQL. It provides a rich web-based interface for managing databases, running queries, visualizing schemas, and handling user roles. Whether you're deploying PostgreSQL locally or managing remote clusters, pgAdmin4 offers a secure and scalable way to interact with your data.
This guide shows you how to install pgAdmin4 on Ubuntu 24.04 using a virtual environment, Gunicorn, and Nginx. This setup is ideal if you want full control over your deployment.
Prerequisites
Before you begin:
- Purchase an Ubuntu 24.04 VPS server. If you don't have a VPS server, sign up with Vultr and get upto $300 worth of free credit to test the Vultr platform.
-
SSH to your VPS server using PuTTY for Windows or run the following command if you're using Linux or Mac.
console$ ssh username@vps_server_public_ip_address -
Create a non-root user with sudo privileges. Read our guide on How to Create a Non-Root Sudo User on Ubuntu 24.04. You'll use this user's account to run the commands in this guide.
- Ensure your domain (For instance,
postgres.example.com) points to your server IP address. - Install Nginx and obtain an SSL certificate via Let's Encrypt.
Create a Python Virtual Environment for pgAdmin4
-
Create and switch to the pgAdmin4 application directory.
console$ mkdir ~/pgadmin4 && cd ~/pgadmin4 -
Create a Python virtual environment.
console$ python3 -m venv venv -
Activate the Python virtual environment.
console$ source venv/bin/activate
Install pgAdmin4
-
Download the latest pgAdmin4 Python wheel package.
console$ wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v9.7/pip/pgadmin4-9.7-py3-none-any.whl -
Install pgAdmin4.
console$ pip install pgadmin4-9.7-py3-none-any.whl -
Install pgAdmin4 dependencies.
console$ pip install gunicorn flask flask-security flask-mail werkzeug -
Create a local configuration file for your pgAdmin4 setup.
console$ nano config_local.pyPaste the following:
Pythonimport os DATA_DIR = os.path.expanduser('~/pgadmin4/data') LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log') SQLITE_PATH = os.path.join(DATA_DIR, 'pgadmin4.db') SESSION_DB_PATH = os.path.join(DATA_DIR, 'sessions') STORAGE_DIR = os.path.join(DATA_DIR, 'storage') -
Save and close the
config_local.pyfile. -
Create the following pgAdmin4 data directories.
console$ mkdir -p ~/pgadmin4/data/sessions ~/pgadmin4/data/storage -
Test pgAdmin4 locally.
console$ gunicorn --bind 127.0.0.1:9000 --workers=1 --threads=25 pgadmin4.pgAdmin4:app
Configure Systemd
-
Create and open systemd service file.
console$ sudo nano /etc/systemd/system/pgadmin4.servicePaste the following.
INI[Unit] Description=pgAdmin4 Gunicorn Service After=network.target [Service] Type=simple User=your_server_username Group=your_server_username WorkingDirectory=/home/your_server_username/pgadmin4 ExecStart=/home/your_server_username/pgadmin4/venv/bin/gunicorn --bind 127.0.0.1:9000 --workers=1 --threads=25 pgadmin4.pgAdmin4:app ExecReload=/bin/kill -s HUP $MAINPID KillMode=mixed Restart=always TimeoutStopSec=5 PrivateTmp=true [Install] WantedBy=multi-user.target -
Save and close the
/etc/systemd/system/pgadmin4.servicefile. -
Reload systemd unit files.
console$ sudo systemctl daemon-reload -
Configure the pgadmin4 service to start automatically at boot.
console$ sudo systemctl enable pgadmin4 -
Start the pgadmin4 service.
console$ sudo systemctl start pgadmin4 -
Verify that pgadmin4 is running.
console$ sudo systemctl status pgadmin4
Configure Nginx
-
Create an Nginx site config:
console$ sudo nano /etc/nginx/sites-available/postgres.example.comPaste the following settings and replace
postgres.example.comwith your domain or subdomain.Nginx Configuration Fileserver { listen 443 ssl; server_name postgres.example.com; ssl_certificate /etc/letsencrypt/live/postgres.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/postgres.example.com/privkey.pem; location / { proxy_pass http://127.0.0.1:9000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_redirect off; } } -
Save and close the
/etc/nginx/sites-available/postgres.example.comfile. -
Enable the new Nginx configuration file.
console$ sudo ln -s /etc/nginx/sites-available/postgres.example.com /etc/nginx/sites-enabled/ -
Ensure there are no errors.
console$ sudo nginx -t -
Reload Nginx to enable the new changes.
console$ sudo systemctl reload nginx
Conclusion
In this guide, you've installed pgAdmin4 on Ubuntu 24.04 using a virtual environment, Gunicorn, and Nginx. This modular setup gives you full control over your PostgreSQL admin interface, with production-grade security and scalability. You've also learned how to daemonize the service with systemd and reverse proxy it behind SSL making your deployment clean, audit-friendly, and ready for global access.