How to Install phpPgAdmin on Ubuntu 22.04

install phppgadmin on ubuntu

In this tutorial, we are going to show you how to install phpPgAdmin on Ubuntu 22.04 OS.

phpPgAdmin is a web-based software used for managing the PostgreSQL database. PostgreSQL is an object-relational database management system. PostgreSQL can be managed through the command line, but for novice users, the better option is phpPgAdmin web-based GUI. In this blog post, we will install the PostgreSQL server first, then the phpPgAdmin. Also, we are going to use the Apache Web server so that you can access phpPgAdmin via the domain name.

For this installation, we will need around 20 minutes. Let’s get started!

Prerequisites

  • A server with Ubuntu 22.04 as OS
  • A valid domain name pointed to the server IP address
  • User privileges: root or non-root user with sudo privileges

Step 1. Update the System

We assume that you have a fresh installation of Ubuntu 22.04. That’s why we need to update the package to the latest versions available.

sudo apt-get update -y && sudo apt-get upgrade -y

Step 2. Install Apache Web Server

Apache Web server can be installed with the following command:

sudo apt install apache2 -y

Once installed, start and enable the service.

sudo systemctl enable apache2.service && sudo systemctl start apache2.service

Check if the service is up and running:

sudo systemctl status apache2.service

You should receive the following output:

root@host:~# sudo systemctl status apache2.service
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-11-25 14:07:33 CST; 3h 36min ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 746 (apache2)
      Tasks: 55 (limit: 4575)
     Memory: 9.7M
        CPU: 871ms
     CGroup: /system.slice/apache2.service
             ├─746 /usr/sbin/apache2 -k start
             ├─844 /usr/sbin/apache2 -k start
             └─845 /usr/sbin/apache2 -k start

Nov 25 14:07:33 host.test.vps systemd[1]: Starting The Apache HTTP Server...
Nov 25 14:07:33 host.test.vps systemd[1]: Started The Apache HTTP Server.

Step 3. Install PHP and extensions

PHP8 with extensions and can be installed with the following commands:

sudo apt-get install php8.1 php8.1-cli php8.1-common php8.1-imap php8.1-redis php8.1-snmp php8.1-xml php8.1-zip php8.1-mbstring php8.1-curl libapache2-mod-php php8.1-mysql -y

To check the installed PHP version, execute the command php -v

root@host:~# php -v
PHP 8.1.2-1ubuntu2.9 (cli) (built: Oct 19 2022 14:58:09) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2-1ubuntu2.9, Copyright (c), by Zend Technologies

Step 4. Install PostgreSQL server

PostgreSQL version 14 is available in the default repository of Ubuntu 22.04, so we just need to execute the command below:

sudo apt install postgresql postgresql-client

Once installed, start and enable the PostgreSQL service.

sudo systemctl enable postgresql.service && sudo systemctl start postgresql.service

Check if the service is up and running:

sudo systemctl status postgresql.service

You should receive the following output:

root@host:~# sudo systemctl status postgresql.service
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Fri 2022-11-25 17:38:33 CST; 2min 36s ago
   Main PID: 3942 (code=exited, status=0/SUCCESS)
        CPU: 2ms

Nov 25 17:38:33 host.test.vps systemd[1]: Starting PostgreSQL RDBMS...
Nov 25 17:38:33 host.test.vps systemd[1]: Finished PostgreSQL RDBMS.

Step 5. Install phpPgAdmin

To install phpPgAdmin, execute the following command:

sudo apt install phppgadmin php-pgsql -y

After the installation, we need to open the phpPgAdmin configuration file /etc/phppgadmin/config.inc.php with our favorite editor and make several changes to look like this:

$conf['extra_login_security'] = true;

$conf['owned_only'] = true;

Save the file and close it.

Step 6. Create an Apache Configuration file

Go into the Apache directory and create a configuration file for the phpPgAdmin.

cd /etc/apache2/sites-available/

touch phppgadmin.conf

Open the file, paste the following lines of code, save it, and close it.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
Alias /phppgadmin /usr/share/phppgadmin

<Directory /usr/share/phppgadmin>
   <IfModule mod_dir.c>
        DirectoryIndex index.php
    </IfModule>
    AllowOverride None

    # Only allow connections from localhost:
    #Require local

   <IfModule mod_php.c>
        php_flag magic_quotes_gpc Off
        php_flag track_vars On
        #php_value include_path .
    </IfModule>
    <IfModule !mod_php.c>
        <IfModule mod_actions.c>
            <IfModule mod_cgi.c>
                AddType application/x-httpd-php .php
                Action application/x-httpd-php /cgi-bin/php
            </IfModule>
            <IfModule mod_cgid.c>
                AddType application/x-httpd-php .php
                Action application/x-httpd-php /cgi-bin/php
            </IfModule>
        </IfModule>
    </IfModule>
</Directory>

Enable the Apache configuration for phpPgAdmin and rewrite the module.

sudo a2enmod rewrite

sudo a2ensite phppgadmin.conf

Check the syntax:

apachectl -t

You should receive the following output:

root@vps:~# apachectl -t
Syntax OK

If the syntax is OK, restart the Apache service.

systemctl reload apache2.service

Once the Apache service is restarted, you can access the phpPgAdmin at http://yourdomain.com/phppgadmin.

phppgadmin on ubuntu 22.04

Congratulations! You just learned how to install phpPgAdmin with Apache on Ubuntu 22.04. Of course, you do not have to install this if you find any difficulties. You can contact our technical support by submitting a support ticket or live chat. We are available 24/7.

If you liked this post on how to phpPgAdmin on Ubuntu 22.04, please share it with your friends on social networks or simply leave a reply below. Thanks.

Leave a Comment