AlmaLinuxRHEL Based

How To Install phpPgAdmin on AlmaLinux 9

Install phpPgAdmin on AlmaLinux 9

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 database administrators and developers. In this comprehensive guide, we’ll walk you through the process of installing phpPgAdmin on AlmaLinux 9, a robust and enterprise-ready Linux distribution.

AlmaLinux 9, being a stable and secure platform, offers an excellent environment for hosting database management tools like phpPgAdmin. By the end of this tutorial, you’ll have a fully functional phpPgAdmin installation, allowing you to manage your PostgreSQL databases with ease.

Prerequisites

Before we begin the installation process, ensure you have the following:

  • An AlmaLinux 9 server with root or sudo access
  • Basic knowledge of command-line operations
  • PostgreSQL database installed (we’ll cover this if you don’t have it)
  • A stable internet connection for downloading packages

It’s also recommended to have a basic understanding of web servers and database concepts. However, we’ll guide you through each step, making it accessible even for beginners.

Update System and Install Dependencies

The first step in any installation process is to ensure your system is up-to-date and has all the necessary dependencies. Let’s start by updating AlmaLinux 9 and installing the required packages.

1. Update AlmaLinux 9

Open your terminal and run the following command to update your system:

sudo dnf update -y

This command will fetch the latest package information and upgrade all installed packages to their latest versions.

2. Install EPEL Repository

The Extra Packages for Enterprise Linux (EPEL) repository provides additional packages that are not included in the default AlmaLinux repositories. Install it using:

sudo dnf install epel-release -y

3. Install Necessary Packages

Now, let’s install the core packages required for phpPgAdmin:

sudo dnf install httpd php php-pgsql php-mbstring php-gd php-xml -y

This command installs Apache web server, PHP, and essential PHP modules for PostgreSQL support and other functionalities required by phpPgAdmin.

Install and Configure Apache Web Server

Apache is one of the most popular web servers and will host our phpPgAdmin installation. Let’s set it up:

1. Start and Enable Apache

After installation, start the Apache service and enable it to start on boot:

sudo systemctl start httpd
sudo systemctl enable httpd

2. Configure Firewall

If you have a firewall enabled, allow HTTP and HTTPS traffic:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

3. Test Apache Installation

Open a web browser and navigate to your server’s IP address or domain name. You should see the default Apache test page, confirming that Apache is running correctly.

Install and Configure PHP

PHP is crucial for running phpPgAdmin. We’ve already installed it, but let’s ensure it’s properly configured:

1. Create a PHP Info File

Create a file named info.php in Apache’s document root:

sudo nano /var/www/html/info.php

Add the following content:

<?php
phpinfo();
?>

2. Test PHP Configuration

Access the PHP info file through your web browser by navigating to http://your_server_ip/info.php. You should see a page displaying PHP configuration information. If it loads correctly, PHP is working with Apache.

3. Remove the PHP Info File

For security reasons, remove the PHP info file after testing:

sudo rm /var/www/html/info.php

Install PostgreSQL (if not already installed)

If you don’t have PostgreSQL installed, follow these steps:

1. Add PostgreSQL Repository

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm

2. Install PostgreSQL

sudo dnf install -y postgresql14-server

3. Initialize PostgreSQL Database

sudo /usr/pgsql-14/bin/postgresql-14-setup initdb

4. Start and Enable PostgreSQL Service

sudo systemctl start postgresql-14
sudo systemctl enable postgresql-14

Install phpPgAdmin

Now that we have all the prerequisites in place, let’s install phpPgAdmin:

1. Download phpPgAdmin

cd /tmp
wget https://github.com/phppgadmin/phppgadmin/releases/download/REL_7-13-0/phpPgAdmin-7.13.0.tar.gz
tar -xzvf phpPgAdmin-7.13.0.tar.gz

2. Move phpPgAdmin Files

sudo mv phpPgAdmin-7.13.0 /var/www/html/phpPgAdmin

3. Configure phpPgAdmin

Copy the sample configuration file:

sudo cp /var/www/html/phpPgAdmin/conf/config.inc.php-dist /var/www/html/phpPgAdmin/conf/config.inc.php

Edit the configuration file:

sudo nano /var/www/html/phpPgAdmin/conf/config.inc.php

Find and modify the following lines:

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

4. Set Up Apache Virtual Host

Create a new Apache configuration file for phpPgAdmin:

sudo nano /etc/httpd/conf.d/phpPgAdmin.conf

Add the following content:

Alias /phpPgAdmin /var/www/html/phpPgAdmin

<Directory /var/www/html/phpPgAdmin>
    AllowOverride All
    Require all granted
</Directory>

5. Restart Apache

sudo systemctl restart httpd

Secure phpPgAdmin

Security is crucial when dealing with database management tools. Let’s implement some basic security measures:

1. Configure Authentication

Edit the Apache configuration file:

sudo nano /etc/httpd/conf.d/phpPgAdmin.conf

Add the following lines inside the <Directory> block:

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

Create a password file and add a user:

sudo htpasswd -c /etc/httpd/.htpasswd your_username

2. Set Up SSL/TLS

For enhanced security, it’s recommended to use HTTPS. You can set up a free SSL certificate using Let’s Encrypt. Follow their documentation to obtain and install a certificate for your domain.

3. Implement Access Controls

You can further restrict access by IP address. Add the following to your Apache configuration:

<Directory /var/www/html/phpPgAdmin>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
    Allow from ::1
    Allow from your_ip_address
</Directory>

Replace your_ip_address with your actual IP address.

Testing phpPgAdmin Installation

Now that we have installed and secured phpPgAdmin, let’s test it:

  1. Open your web browser and navigate to http://your_server_ip/phpPgAdmin (or https:// if you’ve set up SSL).
  2. You should be prompted for the username and password you set up earlier.
  3. After logging in, you’ll see the phpPgAdmin interface.
  4. Try connecting to your PostgreSQL server using the credentials you set during PostgreSQL installation.

If you can log in and see your databases, congratulations! You’ve successfully installed and configured phpPgAdmin on AlmaLinux 9.

Troubleshooting Common Issues

If you encounter problems, here are some common issues and their solutions:

1. Connection Problems

  • Ensure PostgreSQL is running: sudo systemctl status postgresql-14
  • Check PostgreSQL’s pg_hba.conf file for correct connection settings
  • Verify that the host and port in phpPgAdmin’s config match your PostgreSQL settings

2. Authentication Errors

  • Double-check your PostgreSQL username and password
  • Ensure the user has the necessary permissions in PostgreSQL
  • Check Apache logs for any authentication-related errors

3. Permission Issues

  • Verify that Apache has read permissions for phpPgAdmin files
  • Check SELinux settings if you’re using it: sudo sestatus
  • Adjust file ownership if necessary: sudo chown -R apache:apache /var/www/html/phpPgAdmin

Congratulations! You have successfully installed phpPgAdmin. Thanks for using this tutorial for installing the phpPgAdmin web-based administration tool for PostgreSQL on AlmaLinux 9 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