UbuntuUbuntu Based

How To Install phpPgAdmin on Ubuntu 24.04 LTS

Install phpPgAdmin on Ubuntu 24.04

phpPgAdmin is a powerful, web-based administration tool for PostgreSQL databases. It provides an intuitive interface for managing your databases, tables, and data, making it an essential tool for developers and database administrators alike. In this comprehensive guide, we’ll walk you through the process of installing phpPgAdmin on Ubuntu 24.04, ensuring you have a robust platform for managing your PostgreSQL databases with ease.

Prerequisites

Before we begin the installation process, make sure you have the following prerequisites in place:

  • A server running Ubuntu 24.04 LTS
  • Root or sudo access to the server
  • Basic familiarity with Linux command-line operations
  • PostgreSQL database installed on your system (we’ll cover this in the guide if you haven’t installed it yet)

Having these prerequisites in place will ensure a smooth installation process and help you avoid potential roadblocks along the way.

Update and Upgrade Ubuntu System

To begin, let’s ensure your Ubuntu system is up-to-date. Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade -y

These commands will update your package lists and upgrade all installed packages to their latest versions. It’s crucial to keep your system updated to ensure compatibility and security.

Install Apache Web Server

phpPgAdmin requires a web server to function. We’ll use Apache, one of the most popular and reliable web servers available. To install Apache, run:

sudo apt install apache2 -y

After installation, configure the firewall to allow HTTP traffic:

sudo ufw allow in "Apache Full"

Verify that Apache is running by accessing your server’s IP address in a web browser. You should see the default Apache welcome page.

Install PHP and Required Modules

Next, we need to install PHP and the necessary modules for PostgreSQL and Apache integration:

sudo apt install php php-pgsql libapache2-mod-php -y

This command installs PHP, the PostgreSQL module for PHP, and the Apache PHP module. To verify the PHP installation, create a test file:

sudo echo "" | sudo tee /var/www/html/phpinfo.php

Access this file through your web browser (http://your_server_ip/phpinfo.php) to see the PHP configuration information.

Install and Configure PostgreSQL

If you haven’t already installed PostgreSQL, you can do so with the following command:

sudo apt install postgresql postgresql-contrib -y

After installation, create a new PostgreSQL user and database:

sudo -u postgres psql
CREATE USER phppgadmin WITH PASSWORD 'your_password';
CREATE DATABASE phppgadmindb OWNER phppgadmin;
\q

To allow remote connections, edit the PostgreSQL configuration file:

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

Find the line that says listen_addresses and change it to:

listen_addresses = '*'

Save and exit the file, then restart PostgreSQL:

sudo systemctl restart postgresql

Install phpPgAdmin

Now, let’s install phpPgAdmin:

sudo apt install phppgadmin -y

After installation, we need to configure Apache to serve phpPgAdmin. Create a new Apache configuration file:

sudo nano /etc/apache2/conf-available/phppgadmin.conf

Add the following content:

Alias /phppgadmin /usr/share/phppgadmin

<Directory /usr/share/phppgadmin>
    Options FollowSymLinks
    DirectoryIndex index.php
    AllowOverride None
    Require all granted
</Directory>

Save and exit the file, then enable the configuration:

sudo a2enconf phppgadmin
sudo systemctl reload apache2

Configure phpPgAdmin

To configure phpPgAdmin, edit its configuration file:

sudo nano /etc/phppgadmin/config.inc.php

Find the following lines and modify them as needed:

$conf['servers'][0]['host'] = 'localhost';
$conf['servers'][0]['port'] = 5432;
$conf['servers'][0]['defaultdb'] = 'phppgadmindb';

// Set to false if you want to allow anyone to access phpPgAdmin
$conf['extra_login_security'] = false;

Save and exit the file. Remember to set extra_login_security to true in production environments for enhanced security.

Secure phpPgAdmin

To enhance the security of your phpPgAdmin installation, consider implementing the following measures:

  1. Enable SSL/TLS encryption for Apache:
    sudo a2enmod ssl
    sudo systemctl restart apache2
  2. Set up .htaccess protection:
    sudo nano /usr/share/phppgadmin/.htaccess

    Add the following content:

    AuthType Basic
    AuthName "Restricted Access"
    AuthUserFile /etc/phppgadmin/.htpasswd
    Require valid-user

    Create a password file:

    sudo htpasswd -c /etc/phppgadmin/.htpasswd your_username
  3. Regularly update your system and phpPgAdmin to patch any security vulnerabilities.

Accessing and Using phpPgAdmin

To access phpPgAdmin, open your web browser and navigate to:

http://your_server_ip/phppgadmin

Log in using the PostgreSQL username and password you created earlier. Once logged in, you can:

  • Create and manage databases
  • Create, modify, and delete tables
  • Execute SQL queries
  • Import and export data
  • Manage users and permissions

Troubleshooting Common Issues

If you encounter issues while using phpPgAdmin, consider the following troubleshooting steps:

  1. Connection problems: Ensure PostgreSQL is running and listening on the correct port.
  2. Authentication errors: Double-check your PostgreSQL username and password.
  3. Performance issues: Optimize your PostgreSQL configuration and consider increasing server resources if necessary.

Congratulations! You have successfully installed phpPgAdmin. Thanks for using this tutorial for installing the phpPgAdmin web-based administration tool for PostgreSQL on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the phpPgAdmin website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button