@JS's Notes

Site with notes from my work.

PostgreSQL and phpPgAdmin on Ubuntu 20.04

2020-07-17 System @JS

My test platform: Ubuntu Server 20.04

Requirements: user with root privileges or non-root user with sudo privileges.

PostgreSQL and phpPgAdmin installation
$ sudo apt update; sudo apt upgrade -y
$ sudo apt install postgresql postgresql-contrib phppgadmin -y
$ systemctl start postgresql.service
$ systemctl enable postgresql.service
$ systemctl status postgresql.service

Login to the PostgreSQL shell. Create a new role, e.g. pgadmin with the selected password:

$ sudo -i -u postgres psql
postgres=# CREATE ROLE pgadmin WITH SUPERUSER CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWORD 'pass4pg';
postgres=# \du              ## check users
postgres=# \q
Apache configuration

Edit the configuration file /etc/apache2/conf-available/phppgadmin.conf. For security reasons, change the default path URL phppgadmin with your own path e.g. phppga:

Alias /phppga /usr/share/phppgadmin

Change Require local to Require your_subnet. Change your_subnet to your subnet CIDR address:

[...]
# Only allow connections from localhost:
#Require local
Require ip 192.168.1.0/24               ## e.g. subnet
[...]

Test the Apache configuration and restart the Apache service:

$ sudo apachectl configtest
$ sudo systemctl restart apache2.service
Setup UFW firewall
$ sudo ufw allow http comment 'accept HTTP connections'
$ sudo ufw allow https comment 'accept HTTPS connections'
$ sudo ufw allow ssh comment 'accept SSH connections'
$ sudo ufw status

Open your web browser and type the server IP address following with your custom path of phpPgAdmin e.g. http://ip-server/phppga/. Click on the Server tab and you will get the phpPgAdmin login page. Type the PostgreSQL user and password that created on top and click the Login button.