Skip to content

How to install PostgreSQL and phpPgAdmin

This tutorial should work on most of the Ubuntu versions, I have tested it on Ubuntu 18.04

PostgreSQL is a powerful open-source database management system. Its basically a software that manages your database.

phpPgAdmin is a software that allows you to control PostgreSQL via a Graphical User Interface.

Steps for installation

  1. Installing the right softwares
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib 
sudo apt-get install apache2 phppgadmin

2. Configuring Apache2

In order to access phpPgAdmin via your browser, the Apache web server needs to be configured. Therefore open the phppgadmin.conf file:

cd /etc/apache2/conf-available/
sudo vi phppgadmin.conf

Comment out the line Require Local and add Allow from all .

phppgadmin.conf before editing with Require local enabled
Before editing /etc/apache2/conf-available/phppgadmin.conf
phppgadmin.conf after editing with Require local commented out and Allow from all added
After editing /etc/apache2/conf-available/phppgadmin.conf

3. To allow logging into phpPgAdmin using postgres user, tweak some setting of phpPgAdmin

cd /etc/phppgadmin
sudo vi config.inc.php

Set $conf['extra_login_security'] from true to false.

config.inc.php with extra_login_security set to true before editing
Before editing /etc/phppgadmin/config.inc.php
config.inc.php with extra_login_security changed to false
After editing /etc/phppgadmin/config.inc.php

4. Restart the services

sudo service apache2 restart
sudo service postgresql restart

5. Open browser and go to the following url

localhost/phppgadmin

The following screen should be showing up.

phpPgAdmin 5.1 welcome page opened at localhost/phppgadmin
localhost/phppgadmin homepage

Congratulations on successful INSTALLATION of the above softwares. To actually use them, we need to configure the postgreSQL user.

Steps for Logging into postgreSQL using phpPgAdmin

Now the phpPgAdmin is asking for a login and a password. Hmm, why is that? I will try to explain in detail.

PostgreSQL uses concept of role (or simply users) to use the DBMS, i.e. to use postgreSQL you have to log in into this software, same as you need to do in an operating system.

It comes with a default user called postgres that is locked by default to prevent unintentional logging in.

To log in into postgres account, we need to set up its password. Follow the steps.

# Run psql command as postgres user created during 
# installation automatically
sudo -u postgres psql
# Set the password
\password
psql shell as postgres user running \password to set a new password
Password prompt screen to set the password using postgres shell
# Quit postgres
\q

Now you may login at localhost/phppgadmin

Published inLinux