Complete Guide: How to Install PostgreSQL 18 and pgAdmin on AlmaLinux 9 with CyberPanel & LiteSpeed

If you’re running a VPS with AlmaLinux 9, CyberPanel, and LiteSpeed web server, and need to set up PostgreSQL for your applications, this comprehensive guide will walk you through every step. We’ll install the latest PostgreSQL 18, configure it for remote access, and set up pgAdmin for easy database management through a custom domain.

Prerequisites

Before we begin, make sure you have:

  • AlmaLinux 9 VPS with root access
  • CyberPanel installed with LiteSpeed web server
  • A domain pointed to your server (e.g., pgadmin.yourdomain.com)
  • Basic knowledge of SSH and command-line operations

Why PostgreSQL 18?

PostgreSQL 18.1 is the latest stable release (as of November 2025) and brings significant improvements in performance, security, and features. It’s production-ready and perfect for modern web applications.

Step 1: Verify Your System

First, let’s check your system information and confirm PostgreSQL isn’t already installed:

bash
cat /etc/os-release && psql --version

You should see your AlmaLinux version details and a “command not found” error for psql, indicating PostgreSQL isn’t installed yet.

Step 2: Add PostgreSQL Official Repository

 

AlmaLinux’s default repositories don’t include the latest PostgreSQL versions. We’ll add the official PostgreSQL repository:

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

Step 3: Disable Default PostgreSQL Module

AlmaLinux 9 comes with a default PostgreSQL module that conflicts with the official repository. Disable it:

bash
dnf -qy module disable postgresql

This command will also import PostgreSQL GPG keys for package verification.

Step 4: Install PostgreSQL 18

Now install PostgreSQL 18 server and client packages:

bash
dnf install -y postgresql18-server postgresql18

This will install PostgreSQL 18.1 along with all necessary dependencies.

Step 5: Initialize PostgreSQL Database

Initialize the database cluster:

bash
/usr/pgsql-18/bin/postgresql-18-setup initdb

You should see “Initializing database … OK”

Step 6: Start and Enable PostgreSQL Service

Start PostgreSQL and enable it to run on system boot:

bash
systemctl start postgresql-18
systemctl enable postgresql-18
systemctl status postgresql-18

You should see the service as “active (running)” with multiple postgres worker processes.

Step 7: Set PostgreSQL Superuser Password

Access the PostgreSQL console:

bash
sudo -u postgres psql

Set a strong password for the postgres user (replace with your own secure password):

sql
ALTER USER postgres WITH PASSWORD 'your_strong_password_here';

Exit the console:

sql
\q

Step 8: Configure PostgreSQL for Remote Access

Edit postgresql.conf

Open the main configuration file:

bash
nano /var/lib/pgsql/18/data/postgresql.conf

Press Ctrl+W to search for listen_addresses, then uncomment and change it to:

listen_addresses = '*'

Save and exit: Ctrl+X, then Y, then Enter

Edit pg_hba.conf

Open the authentication configuration file:

bash
nano /var/lib/pgsql/18/data/pg_hba.conf

Scroll to the bottom and add these lines:

# Allow connections from anywhere with password
host    all             all             0.0.0.0/0               scram-sha-256
host    all             all             ::/0                    scram-sha-256

Save and exit: Ctrl+X, then Y, then Enter

Restart PostgreSQL

Apply the changes:

bash
systemctl restart postgresql-18

Step 9: Configure Firewall

Open port 5432 in CyberPanel:

  1. Go to CyberPanel → Security → Firewall
  2. Add port 5432 for TCP
  3. Apply the changes

Verify PostgreSQL is listening:

bash
ss -tulpn | grep 5432

You should see PostgreSQL listening on 0.0.0.0:5432 and [::]:5432

Step 10: Install pgAdmin 4

Add pgAdmin Repository

bash
dnf install -y https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-2-1.noarch.rpm

Install pgAdmin 4 Web

bash
dnf install -y pgadmin4-web

This will install pgAdmin along with Apache (httpd) as a dependency.

Setup pgAdmin

Run the setup script:

bash
/usr/pgadmin4/bin/setup-web.sh

When prompted:

  • Enter your email address (e.g., [email protected])
  • Set a strong password
  • Type y to enable and start Apache

Note: Apache may fail to start because LiteSpeed is using port 80. This is expected – we’ll fix it next.

Step 11: Configure Apache to Run on Different Port

Since LiteSpeed is using port 80, we’ll run Apache on port 8081.

Edit Apache Configuration

bash
nano /etc/httpd/conf/httpd.conf

Search for Listen 80 (press Ctrl+W) and change it to:

Listen 8081

Save and exit.

Open Port 8081 in Firewall

In CyberPanel:

  1. Go to Security → Firewall
  2. Add port 8081 for TCP
  3. Apply changes

Start Apache

bash
systemctl start httpd
systemctl enable httpd
systemctl status httpd

Verify Apache is running on port 8081.

Step 12: Setup Custom Domain with LiteSpeed Reverse Proxy

Create Website in CyberPanel

  1. Log into CyberPanel
  2. Go to Websites → Create Website
  3. Enter:
    • Domain: pgadmin.yourdomain.com
    • Email: your email
    • Select a package
  4. Click Create Website

Point DNS

Create an A record for pgadmin.yourdomain.com pointing to your server IP.

Configure LiteSpeed Reverse Proxy

  1. In CyberPanel, go to Websites → List Websites
  2. Find pgadmin.yourdomain.com and click Manage
  3. Click on “vHost Conf”
  4. Add this external processor configuration before the phpIniOverride section:
apache
extprocessor pgadmin_proxy {
  type                    proxy
  address                 http://127.0.0.1:8081
  maxConns                100
  pcKeepAliveTimeout      60
  initTimeout             60
  retryTimeout            0
  respBuffer              0
}
  1. Add this context configuration after the existing context / block:
apache
context /{
  type                    proxy
  handler                 pgadmin_proxy
  addDefaultCharset       off
}
  1. Save the configuration
  2. Restart LiteSpeed:
bash
systemctl restart lsws

Step 13: Configure pgAdmin to Serve on Root Path

To access pgAdmin directly at https://pgadmin.yourdomain.com instead of https://pgadmin.yourdomain.com/pgadmin4:

Edit pgAdmin Apache Configuration

bash
nano /etc/httpd/conf.d/pgadmin4.conf

Change this line:

WSGIScriptAlias /pgadmin4 /usr/pgadmin4/web/pgAdmin4.wsgi

To:

WSGIScriptAlias / /usr/pgadmin4/web/pgAdmin4.wsgi

Save and exit, then restart Apache:

bash
systemctl restart httpd

Step 14: Access pgAdmin

Open your browser and navigate to:

https://pgadmin.yourdomain.com

Log in with the email and password you set during pgAdmin setup.

Step 15: Connect PostgreSQL to pgAdmin

  1. In pgAdmin, right-click “Servers” in the left sidebar
  2. Select Register → Server
  3. In the “General” tab:
    • Name: Production PostgreSQL 18
  4. In the “Connection” tab:
    • Host: localhost or 127.0.0.1
    • Port: 5432
    • Maintenance database: postgres
    • Username: postgres
    • Password: (your postgres password)
    • Check “Save password” (optional)
  5. Click Save

You should now see your PostgreSQL server connected in pgAdmin!

Security Best Practices

  1. Change Default Passwords: Always use strong, unique passwords
  2. Restrict Remote Access: If you don’t need remote database access, remove the 0.0.0.0/0 rules from pg_hba.conf
  3. Enable SSL: Configure PostgreSQL to use SSL for encrypted connections
  4. Regular Updates: Keep PostgreSQL and pgAdmin updated
  5. Firewall Rules: Only open necessary ports and restrict access by IP when possible
  6. Regular Backups: Set up automated database backups

Troubleshooting Common Issues

Apache Won’t Start

Problem: Port 80 is already in use by LiteSpeed

Solution: Configure Apache to use port 8081 as described in Step 11

Can’t Connect to PostgreSQL Remotely

Problem: Firewall blocking port 5432

Solution: Ensure port 5432 is open in CyberPanel firewall

403 Forbidden Error in pgAdmin

Problem: Incorrect proxy configuration

Solution: Follow Step 12 carefully and ensure the external processor and context are properly configured

pgAdmin Login Loop

Problem: Session configuration issues

Solution: Clear browser cache and cookies, try incognito mode

Useful Commands

Check PostgreSQL status:

bash
systemctl status postgresql-18

View PostgreSQL logs:

bash
tail -f /var/lib/pgsql/18/data/log/postgresql-*.log

Check Apache status:

bash
systemctl status httpd

Check listening ports:

bash
ss -tulpn | grep -E '5432|8081'

Restart services:

bash
systemctl restart postgresql-18
systemctl restart httpd
systemctl restart lsws

Conclusion

You now have a fully functional PostgreSQL 18 installation with pgAdmin accessible through a custom domain on your AlmaLinux 9 server running CyberPanel and LiteSpeed. This setup allows you to:

  • Deploy PostgreSQL-based applications
  • Manage databases through a user-friendly web interface
  • Access pgAdmin securely via HTTPS
  • Scale your database operations as needed

PostgreSQL 18 brings enhanced performance and new features that make it an excellent choice for modern web applications. Combined with pgAdmin’s intuitive interface and CyberPanel’s management capabilities, you have a powerful database infrastructure ready for production use.

case studies

See More Case Studies

Energy & Utilities

Optimize asset maintenance and manage critical information and operations with Utility industry solutions from OpenText. Challenges with Energy & Utilities Industry The modern utility faces

Learn more

Advertising

To help you amplify brand reach, engage your audience, win new customers, and measure advertising impact. Challenges with advertising Results that provide a positive return

Learn more
Contact us

Partner with Us for Comprehensive IT

We’re happy to answer any questions you may have and help you determine which of our services best fit your needs.

Your benefits:
What happens next?
1

We Schedule a call at your convenience 

2

We do a discovery and consulting meting 

3

We prepare a proposal 

Schedule a Free Consultation