Installing and Configuring PostgreSQL in Ubuntu

The installation command in Ubuntu:

sudo apt-get install postgresql postgresql-client postgresql-contrib

You can install a graphical client for easy management:

sudo apt-get install pgadmin3


sudo apt-get install phppgadmin

To access from outside, open the configuration file (Ctrl + X to exit):

sudo nano /etc/postgresql/9.3/main/postgresql.conf

And uncomment the line:

listen_addresses = 'localhost'

In the pg_hba.conf file, we specify which addresses are allowed access:

host all all md5

Restart PostgreSQL so that the changes to the configuration files take effect:

sudo service postgresql restart

Here is the password for the postgres user:

sudo -u postgres psql
ALTER USER postgres with encrypted password 'PASSWORD';

An example of testing a connection from a remote computer:

psql -h СЕРВЕР -U postgres -W

If PostgreSQL is to be used with Apache2, then we’ll install the other components:

sudo apt-get install apache2 libapache2-mod-php5 php5 php5-common php5-gd php5-pgsql