pgAdmin can be deployed as a web server therefore user doesn’t need to install any client to access DB. This also provides a securer way of accessing your database:  suppose your web server is on the same network as your DB server, you can setup firewall rules to allow access to the web server on port 80 only, you don’t need to open port on DB server for public access.

The documentation (https://www.pgadmin.org/docs/pgadmin4/1.x/server_deployment.html)  on how to deploy pgAdmin as web server is quite brief, it doesn’t show much detail about what to do after you download the whl installation file on Linux.

Below are end-to-end steps to help you deploy pgAdmin as a web service. The environment is Ubuntu 16, Apache2, Python 3.5, mod_wsgi, venv (virtual environment) and pgAdmin4

  1. Download pgAdmin4
  2. Create a virtual environment, in this case

  1. Once the above is run, pgadmin is a virtual environment that holds a copy of all Python3 executables. From now on, this virtual environment is separate from your system default Python.
  2. Activate this environment

 

  1. Now put pgAdmin.whl into this folder and install it

 

  1. After installation, pgAdmin is put under /var/www/virtual_environments/pgadmin/lib/python3.5/site-packages/pgadmin4

This is an inconvenient place but it reflects the fact that from Python’s perspective, pgAdmin is just a site specific module. As the whole purpose of creating the virtual environment was to hold pgAdmin, we’ll move it to a better location later.

  1. Configure pgAdmin, follow the steps described under Python section. Instead of putting files(such as pgadmin4.db, pgadmin4.log) under /var/lib, you can put all those under the virtual_environments/pgadmin folder.
  2. Ensure the following are writable by www-data (Apache’s run user), as well as their parent folder (this is a MUST otherwise you’ll probably get “sqlite3.OperationalError: unable to open database file” error)

  1. enable mod_wsgi. Note we use wsgi3 for Python 3

  1. Create a site configuration file under /etc/apache2/sites-available

Note the above the use of python-home and python-path

  1. Enable Apache site

  1. Restart Apache

 

  1. Now if you go to /pgadmin on your browser, you should be able to see the login page
  2. Now it’s time to revisit the location of pgAdmin
  3. Create folder /var/www/virtual_environments/pgadmin/web and move everything under //var/www/virtual_environments/pgadmin/lib/python3.5/site-packages/pgadmin4 to this folder

a. Modify sites-enabled/pgadmin.conf

b. Now reload pgadmin.conf

 

Deploy pgAdmin as a web service under venv environment
Tagged on:                             

Leave a Reply

Your email address will not be published. Required fields are marked *

77 − = 68

This site uses Akismet to reduce spam. Learn how your comment data is processed.