How to install pgAdmin 4 in server mode on Ubuntu 16.04

How to install pgAdmin 4 on Ubuntu 16.04 ? Lack of information on homepage.

https://www.pgadmin.org/ https://www.postgresql.org/ftp/pgadmin3/pgadmin4/


Solution 1:

These are the steps I followed to make it run:

1) I didn't have virtualenvwrapper installed, so I (duh!) installed it

sudo pip install virtualenvwrapper

2) Standing on my home folder, I made a pgadmin virtual environment, which creates a pgadmin folder, inside of which I tell it to activate itself

cd ~
virtualenv pgadmin
cd pgadmin
source bin/activate

3) Inside my virtual environment, I make sure to have required dependencies so I'd be able to build wheel for pycrypto and psycopg2

sudo apt-get install build-essential libssl-dev libffi-dev python-dev libgmp3-dev
sudo pip install cryptography pyopenssl ndg-httpsclient pyasn1 

4) Having the required deps, now I can download and pip install the latest pgadmin4 release

wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v1.4/pip/pgadmin4-1.4-py2.py3-none-any.whl

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

5) pgAdmin4 is installed in my virtualenv, now I need to create a config_local.py in the same folder it was installed, and I will use config.pyas the base. So, let's find that one first:

find . -wholename "*pgadmin4/config.py"

6) It tells me it's in ./lib/python2.7/site-packages/pgadmin4/config.py so now I can copy it and run pgAdmin4:

cp ./lib/python2.7/site-packages/pgadmin4/config.py ./lib/python2.7/site-packages/pgadmin4/config_local.py
python  ./lib/python2.7/site-packages/pgadmin4/pgAdmin4.py

The webapp is now running at http://localhost:5050

### EDIT ###

To avoid updating this thread each time a new version of pgAdmin4 is released, i made a pgadmin4_installer repo at GitHub with:

  • a detailed README.md
  • an AptFile with system packages to install
  • Makefile tasks to create virtualenvs specific to python2 or python3, according to your preference
  • Makefile tasks to install requirements (python2 or python3)
  • Instructions to run as an uwsgi script
  • Instructions to create an uwsgi service with autostart on reboots

Solution 2:

Those are the instructions to install in Server mode. For Desktop mode, see How to install pgAdmin 4 in desktop mode on Ubuntu 16.04.

For pgAdmin 4 v1.4 on Ubuntu 16.04, according to the download page:

Install dependencies, create a virtual environment, download, install & configure

sudo apt-get install virtualenv python-pip libpq-dev

cd
virtualenv pgadmin4
cd pgadmin4
source bin/activate

wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v1.4/pip/pgadmin4-1.4-py2.py3-none-any.whl

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

gedit lib/python2.7/site-packages/pgadmin4/config_local.py

Configure lib/python2.7/site-packages/pgadmin4/config_local.py

# Minimum configuration for config_local.py
CSRF_SESSION_KEY = 'Change this now'
SECRET_KEY = 'Change this now'
SECURITY_PASSWORD_SALT = 'Change this now'

Run

cd ~/pgadmin4
source bin/activate
python lib/python2.7/site-packages/pgadmin4/pgAdmin4.py

Access at http://localhost:5050

Solution 3:

One way to install pgadmin4 is to download its Python wheel at https://www.postgresql.org/ftp/pgadmin3/pgadmin4/v1.0-beta1/pip/ and then use pip to install it:

wget https://ftp.postgresql.org/pub/pgadmin3/pgadmin4/v1.0-beta1/pip/pgadmin4-1.0_beta1-py2-none-any.whl
pip install pgadmin4-1.0_beta1-py2-none-any.whl

Note that the wheel only works for Python 2. If you get an error message that says "Error: pg_config executable not found.", install pg_config by running sudo apt-get install libpq-dev according to https://stackoverflow.com/q/11618898/486919.

According to https://www.pgadmin.org/download/pip4.php, to run pgadmin4, do the following:

Once installed, you will need to create a config_local.py file in the same directory as config.py. On a machine with a virtual environment created at ~/pgadmin4, this is ~/pgadmin4/lib/python2.7/site-packages/pgadmin4. Ensure you set values for the SECRET_KEY, SECURITY_PASSWORD_SALT and CSRF_SESSION_KEY settings at bare minimum - see config.py for more information and other settings that can be customised. In order to reference other variables from config.py, you may need to include from config import * at the top of config_local.py.

pgAdmin can now be run with a command like python ~/pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py. Finally, point your browser to http://127.0.0.1:5050.