Installing pgAdmin 4 in Server Mode on Debian 12 with Nginx and Gunicorn
pgAdmin 4 is a popular open-source administration tool for PostgreSQL databases. It can be installed in two modes: web-based and server-based. In this article, we will focus on installing pgAdmin 4 in server mode on Debian 12 using Nginx and Gunicorn.
Prerequisites
Before we start, make sure you have the following installed:
- Debian 12 (or a Debian-based distribution)
- PostgreSQL
- Python 3.x
- Virtualenv
- Nginx
Installing pgAdmin 4
First, create a virtual environment and activate it:
$ virtualenv pgadmin4
$ source pgadmin4/bin/activate
Now, clone the pgAdmin 4 repository:
$ git clone https://github.com/pgadmin-org/pgadmin4.git
Navigate to the cloned repository:
$ cd pgadmin4
Install the required dependencies:
(pgadmin4) $ pip install -r requirements.txt
Generate a configuration file:
(pgadmin4) $ python pgAdmin4/setup.py --create-dirs
Now, we need to configure pgAdmin 4. Open the configuration file:
(pgadmin4) $ nano config_distro.py
Find the following lines and modify them as needed:
# Web application settings
WEBSERVER_ADDRESS = '0.0.0.0'
WEBSERVER_PORT = 5050
Make sure to open the specified port in your firewall.
Installing Gunicorn
Install Gunicorn:
(pgadmin4) $ pip install gunicorn
Test Gunicorn:
(pgadmin4) $ gunicorn --bind 0.0.0.0:5050 pgAdmin4.wsgi:application
You should now be able to access pgAdmin 4 at
Configuring Nginx
Create a new Nginx configuration file:
$ sudo nano /etc/nginx/sites-available/pgadmin4
Add the following configuration:
server {
listen 80;
server\_name pgadmin.example.com;
location / {
proxy\_pass http://localhost:5050;
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;
}
}
Enable the Nginx configuration:
$ sudo ln -s /etc/nginx/sites-available/pgadmin4 /etc/nginx/sites-enabled/
Test the Nginx configuration:
$ sudo nginx-t
In this article, we learned how to install pgAdmin 4 in server mode on Debian 12 using Nginx and Gunicorn. We discussed the prerequisites, cloning the repository, installing the required dependencies, generating a configuration file, installing Gunicorn, configuring Nginx, and testing the setup.