Install pgAdmin4 v3.2 in server mode on ubuntu 16/18 with HTTPS on apache2


Install pgAdmin4 v3.2 in server mode on ubuntu 16/18 with HTTPS on apache2

Hi Tech Guys,

this is a small tutorial that will help your installation of pgAdmin 4 v3.2+ in Ubuntu server 16/18 on Apache2 webserver with a secure connection HTTPS, i will use a self-signed certificate, but you can change it with your own.

If you have some trouble to make it work, DO NOT HESITATE to comment here, feel free to ask.

Anyway we realized a small video located on the bottom of this guide.



-Ubuntu server 16 or 18 with minimal hardware configuration (depends of your needs).

-ROOT permission on server.

-Internet connection to download all needed packages.

-Small IT basic knowledge and a bit of patience…

Let’s Start!

First of all update server repo list

sudo apt-get update

Change hostname at your server if needed

hostnamectl set-hostname pgadmin.yobicloud.local

Install POSTGRESQL packages if is not already installed

sudo apt-get install postgresql postgresql-contrib

Here is the repo if you need to do it manually “

After DB installation change the password of your user postgres for the postgres DB

sudo -u postgres psql postgres
\password postgres

Insert your password twice and quit


Now we are ready to prepare dependency  to install last pgAdmin4 version from official Postgresql repo

sudo apt-get install build-essential libssl-dev libffi-dev libgmp3-dev virtualenv python-pip libpq-dev python-dev

Chose the path where Pgadmin will be installed, i use home, and setup a hidden folder with virtualenv move in and activate it

virtualenv .pgadmin4
cd .pgadmin4
source bin/activate

Now install with pip all pgadmin4 dependency

pip install flask-htmlmin
pip install wheel
pip install cryptography pyopenssl ndg-httpsclient pyasn1

Now we are ready to download and install last pgAdmin4 version from offical repo

pip install pgadmin4-3.2-py2.py3-none-any.whl

If you receive some error try with sudo

sudo pip install pgadmin4-3.2-py2.py3-none-any.whl

Once is installed let’s configure it

sudo nano /home/ubu/.pgadmin/lib/python2.7/site-packages/pgadmin4/

And edit the line DEFAULT_SERVER this text or your specific IP:

DEFAULT_SERVER = '' or ip address server

Now create a file to specific the destination of software data

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'

Now is time to run Pgadmin4 and if show to connect to after user and password setup everything went smooth, you can test it or stop here if SSL is not needed

sudo python /home/ubu/.pgadmin4/lib/python2.7/site-packages/pgadmin4/
Email address: admin@yobicloud.local
Password:Type the Password
Retype password:Retype the Password
pgAdmin 4 - Application Initialisation

CTRL+C   to shutdown pgadmin

Deactivate virtualenv in the folder


Set the proper permission to write in the folders

sudo chown -R www-data:www-data /var/lib/pgadmin4/
sudo chown -R www-data:www-data /var/log/pgadmin4/

Install Apache2 if is not already installed

sudo apt-get install apache2 apache2-utils libexpat1 ssl-cert python curl
sudo apt-get install libapache2-mod-wsgi
sudo systemctl restart apache2

Edit apache2 configuration to redirect all pgAdmin4 connection from port 80 to 443 or whatever you chose by creating conf files

sudo nano pgadmin4.conf
<VirtualHost *:80>
ServerName ubuntu.yobicloud.local[or IP]
Redirect permanent / https://[IP or hostname]/login?next=%2F
<VirtualHost _default_:443>
ServerName pgadmin.yobicloud.local
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/pgadmin4.crt
SSLCertificateKeyFile /etc/apache2/ssl/pgadmin4.key
WSGIDaemonProcess pgadmin processes=1 threads=25
WSGIScriptAlias / /home/ubu/.pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.wsgi
<Directory "/home/ubu/.pgadmin4/lib/python2.7/site-packages/pgadmin4/">
WSGIProcessGroup pgadmin
WSGIApplicationGroup %{GLOBAL}
Require all granted


Remove apache default conf files and link the pgadmin4.conf you created

cd /etc/apache2/sites-enabled/
sudo rm -r 000-default.conf
sudo ln -s ../sites-available/pgadmin4.conf .

Generate the certificate and fill in all info of the wizard (the path of the certificates is already in the pgadmin.conf apache file)

sudo mkdir /etc/apache2/ssl
sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/apache2/ssl/pgadmin4.key -out /etc/apache2/ssl/pgadmin4.crt

Set SSL mode restart apache2 and enable it at OS boot

sudo a2enmod ssl
sudo systemctl restart apache2
sudo systemctl status apache2
sudo systemctl enable apache2
apachectl configtest

Open your browser and write the ip address or hostname of your pgAdmin4 installed machine

—>>> ENJOY!!! <<<—

About the author



YOBIHAT TEAM is a group of expertise IT (Programmers, System & Network engineer, Optic Fiber Technician, Graphics, Blogger and Users) who follow Open Source philosophy, and will drive you in deep with the YOBICLOUD platform for DevOps.