There is a new version of this tutorial available for Ubuntu 20.04 (Focal Fossa).

How to Install PostgreSQL and phpPgAdmin on Ubuntu 18.04 LTS

PostgreSQL or Postgres is a powerful high-performance object-relational database management system (ORDBMS) released under a flexible BSD-style license. PostgreSQL is well suited for large databases and has many advanced features.

PostgreSQL is available for many operating systems including Linux, FreeBSD, Solaris, and Microsoft Windows. PhpPgAdmin is a PHP-based web application for managing PostgreSQL databases. With Phppgadmin, it is easy to create a database, create a role and create tables in Postgres.

This tutorial will show the installation of PostgreSQL and its web-based administration interface phpPgAdmin on Ubuntu 18.04 LTS (Bionic Beaver). I will use the Ubuntu minimal server as a basis for this setup.


  • Ubuntu 18.04
  • Root privileges

What we will do?

  1. Install PostgreSQL and phpPgAdmin
  2. Configure Postgres User
  3. Configure Apache2
  4. Configure phpPgAdmin
  5. Testing

Step 1 - Install PostgreSQL, phpPgAdmin and All Dependencies

Before installing any packages on the Ubuntu system, update all available repositories.

sudo apt update

And now we're ready for installing PostgreSQL, phpPgAdmin, and Apache2 packages.

PostgreSQL and PhpPgAdmin are available in the Ubuntu repository. So you just need to install them with the apt command.

sudo apt -y install postgresql postgresql-contrib phppgadmin

The above command will automatically install all packages needed by PostgreSQL and phpPgAdmin, like Apache2, PHP etc.

Step 2 - Configure Postgres User

PostgreSQL uses role for user authentication and authorization, it just like Unix-Style permissions. By default, PostgreSQL creates a new user called "postgres" for basic authentication. To use PostgreSQL, you need to login to the "postgres" account, you can do that by typing:

su - postgres

Now you can access the PostgreSQL prompt with the command:


And then change the password for postgres role by typing:

\password postgres

Then enter \q to leave the psql command line.


Run the command "exit" to leave the postgres user and become root again.


Set a PostgreSQL password

Step 3 - Configure Apache Web Server

You need to configure Apache virtual host configuration for phpPgAdmin.

Goto the '/etc/apache2/conf-available' directory and edit the configuration file 'phppgadmin.conf' with vim by typing:

cd /etc/apache2/conf-available/
vim phppgadmin.conf

Comment out the line '#Require local' by adding a # in front of the line and add below the line allow from all so that you can access from your browser.

Require all granted

Save and exit.

Configure Apache Web server

Step 4 - Configure phpPgAdmin

Go to the '/etc/phppgadmin' directory and edit the configuration file '' by typing :

cd /etc/phppgadmin/

Find the line '$conf['extra_login_security'] = true;' and change the value to 'false' so you can login to phpPgAdmin with user postgres.

$conf['extra_login_security'] = false;

Save and exit.

Configure phpPgAdmin

Now restart the PostgreSQL and Apache2 services.

systemctl restart postgresql
systemctl restart apache2

Step 5 - Testing Postgres

By default, PostgreSQL is running on port '5432', and the Apache2 running on the default HTTP port '80'.

Check using netstat command.

netstat -plntu

Check postgres network

Now access phpPgAdmin with your browser http://yourip/phppgadmin/.

Login to phpPgAdmin

and then try login to with user 'postgres' and your password.

Login with postgres user to phpPgAdmin

After logging in, you will get this phpPgAdmin dashboard interface:

phpPgAdmin dashboard interface

Installation of the PostgreSQL database with phpPgAdmin on Ubuntu 18.04 LTS has been completed successfully.


PostgreSQL is an advanced object-relational database management system (ORDBMS). It is Open Source and has a large and active community. PostgreSQL provides the psql command line program as primary front-end, which can be used to enter SQL queries directly or execute them from a file. phpPgAdmin is a web-based administration tool for PostgreSQL written in PHP that makes the administration of Postgres databases easier.

Share this page:

Suggested articles

18 Comment(s)

Add comment


By: Chell0h


Kindly correct the spelling of this line "systemctl restart posqtgresql" to read "systemctl restart postgresql" so that the code can work well.

By: Gabe

Thanks, it worked on Kubuntu 18.04.

By: Agbonze Prince

Thanks for this. Works like charm.. I truly appreciate

By: FiddleWalker

Thank you, Muhammad Arul. Fantastically smooth-working implementation description!

By: akiragila

i encountered this error: "unable to locate phppgadmin", when trying to install phppgadmin. Can you help me on this?

By: Jason

Same issue...


sudo apt-get install phppgadmin

Reading package lists... Done

Building dependency tree

Reading state information... Done

E: Unable to locate package phppgadmin

By: till

The package is definitely there, just installed it on Ubuntu 18.04. Probably you don't have all Ubuntu repositories (restricted + universe + multiverse) enabled. The /etc/apt/sources.list file on your server should contain this:


# deb cdrom:[Ubuntu-Server 18.04 LTS _Bionic Beaver_ - Release amd64 (20180425.1)]/ bionic main restricted


#deb cdrom:[Ubuntu-Server 18.04 LTS _Bionic Beaver_ - Release amd64 (20180425.1)]/ bionic main restricted


# See for how to upgrade to

# newer versions of the distribution.

deb bionic main restricted

# deb-src bionic main restricted


## Major bug fix updates produced after the final release of the

## distribution.

deb bionic-updates main restricted

# deb-src bionic-updates main restricted


## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu

## team. Also, please note that software in universe WILL NOT receive any

## review or updates from the Ubuntu security team.

deb bionic universe

# deb-src bionic universe

deb bionic-updates universe

# deb-src bionic-updates universe


## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu

## team, and may not be under a free licence. Please satisfy yourself as to

## your rights to use the software. Also, please note that software in

## multiverse WILL NOT receive any review or updates from the Ubuntu

## security team.

deb bionic multiverse

# deb-src bionic multiverse

deb bionic-updates multiverse

# deb-src bionic-updates multiverse


## N.B. software from this repository may not have been tested as

## extensively as that contained in the main release, although it includes

## newer versions of some applications which may provide useful features.

## Also, please note that software in backports WILL NOT receive any review

## or updates from the Ubuntu security team.

deb bionic-backports main restricted universe multiverse

# deb-src bionic-backports main restricted universe multiverse


## Uncomment the following two lines to add software from Canonical's

## 'partner' repository.

## This software is not part of Ubuntu, but is offered by Canonical and the

## respective vendors as a service to Ubuntu users.

# deb bionic partner

# deb-src bionic partner


deb bionic-security main restricted

# deb-src bionic-security main restricted

deb bionic-security universe

# deb-src bionic-security universe

deb bionic-security multiverse

# deb-src bionic-security multiverse

By: Jens

Thanks for this. There is a typo in line

systemctl restart posqtgresql

By: till

Thanks! Fixed the typo.

By: Steve

These are quite clear instructions.

I followed them all and still get "Login disallowed for security reasons."  I checked the editing of the extra_login_security to false, and restarted postgresql and apache2 services twice.

By: Jason Jonathan

Thanks for sharing the details for assisting me in installing PostgreSQL.

By: Aibek

su - postgres

you cannot login as postgres user from default user login.previously you need run "sudo su" and enter your system password!!!

By: Rob

sudo apt -y install

The -y goes after 'install'

By: Vinay Menon

It worked for me, some initial hiccups and then I could trouble shoot my way. Thanks

By: Dav

Great help, worked like a charm. Really appreciate your effort writing this. Ubuntu 18.04

By: Alessandro

Hi guys!I can't conect postgres user on phppgadmin

a revised all topics


By: jes

worked well thank u!

By: kautsar

hello, i want to ask something, how if i use tomcat as webserver and how i config it in this step use this tutorial to build tomcat webserver you answer, thanks for your attention before, regrads kautsar