Installing And Using PhpPgAdmin On Ubuntu

By:   –  Last updated:   –  #postgresql ·  #phppgadmin ·  #ubuntu

Code Theme [Dark]

Content Overview [Hide]

PhpPgAdmin is a powerful web interface to manage PostgreSQL, which can be compared with the MySQL web-based administration tool: PhpMyAdmin.

1 Installation

Installing phpPgAdmin with apt:

$ sudo apt-get install phppgadmin

If you haven't had php and apache installed on your Ubuntu server, above command will automatically install php and apache for you.

2 Configure Apache

After installation, there's already an apache vhost configuration file for phpPgAdmin which is located in /etc/apache2/conf.d/phppgadmin. We will edit this file and change some configurations.

$ sudo vim /etc/apache2/conf.d/phppgadmin

In order to access from web, we'd better comment following two lines in /etc/apache2/conf.d/phppgadmin file:

# deny from all
# allow from 127.0.0.0/255.0.0.0 ::1/128

And uncomment or add the allow directive:

allow from all

The next step is to enable this vhost configuration. There are two optional ways.

The first method is to let apache include phppgadmin vhost in its configuration file.

$ sudo vim /etc/apache2/apache2.conf

Add the following line to apache2.conf:

Include /etc/apache2/conf.d/phppgadmin

The second method is to create a symbol link:

$ sudo ln -s /etc/apache2/conf.d/phppgadmin /etc/apache2/sites-enabled/phppgadmin

Whatever method you choose, you should restart apache service to reload the changes.

$ sudo service apache2 restart

3 Configure phpPgAdmin

The configuration file for phpPgAdmin is /etc/phppgadmin/config.inc.php. Open this file in terminal:

$ sudo vim /etc/phppgadmin/config.inc.php

Because our PostgreSQL is installed on the same server, so change the host setting:

$conf['servers'][0]['host'] = 'localhost';

then find the extra login security setting line:

$conf['extra_login_security'] = true;

Change it to false:

$conf['extra_login_security'] = false;

If you keep it to be true, you can't login phpPgAdmin in the web interface even your account and password is correct. phpPgAdmin will disallow you signin with an error message: "Login disallowed for security reasons". This is a common issue when installing phpPgAdmin.

If you want phpPgAdmin to automatically hide databases that don't belong to the current user signed in, you have to change the owned_only setting. Find the line:

$conf['owned_only'] = false;

And change it to true:

$conf['owned_only'] = true;

4 Common Issues

4.1 "Login disallowed for security reasons"

As mentioned above, this error is caused by setting extra_login_security to true in /etc/phppgadmin/config.inc.php. Setting it to false can solve the error.

4.2 Don't know the default passowrd

The default user is postgres after installing PostgreSQL. You can set or update its password of accessing database via command line.

Connect PostgreSQL shell:

$  sudo -u postgres psql

then you will enter the psql shell prompt:

postgres=# 

Set password by the command \passoword:

postgres=# \password postgres

Alternatively, you can also set the password by SQL command:

postgres=# ALTER USER postgres WITH PASSWORD 'your new password here'

After any changes of configuraion, you'd better restart the PostgreSQL service:

$ sudo service postgresql restart