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:
cat /etc/os-release && psql --versionYou 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:
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpmStep 3: Disable Default PostgreSQL Module
AlmaLinux 9 comes with a default PostgreSQL module that conflicts with the official repository. Disable it:
dnf -qy module disable postgresqlThis command will also import PostgreSQL GPG keys for package verification.
Step 4: Install PostgreSQL 18
Now install PostgreSQL 18 server and client packages:
dnf install -y postgresql18-server postgresql18This will install PostgreSQL 18.1 along with all necessary dependencies.
Step 5: Initialize PostgreSQL Database
Initialize the database cluster:
/usr/pgsql-18/bin/postgresql-18-setup initdbYou should see “Initializing database … OK”
Step 6: Start and Enable PostgreSQL Service
Start PostgreSQL and enable it to run on system boot:
systemctl start postgresql-18
systemctl enable postgresql-18
systemctl status postgresql-18You should see the service as “active (running)” with multiple postgres worker processes.
Step 7: Set PostgreSQL Superuser Password
Access the PostgreSQL console:
sudo -u postgres psqlSet a strong password for the postgres user (replace with your own secure password):
ALTER USER postgres WITH PASSWORD 'your_strong_password_here';Exit the console:
\qStep 8: Configure PostgreSQL for Remote Access
Edit postgresql.conf
Open the main configuration file:
nano /var/lib/pgsql/18/data/postgresql.confPress 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:
nano /var/lib/pgsql/18/data/pg_hba.confScroll 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-256Save and exit: Ctrl+X, then Y, then Enter
Restart PostgreSQL
Apply the changes:
systemctl restart postgresql-18Step 9: Configure Firewall
Open port 5432 in CyberPanel:
- Go to CyberPanel → Security → Firewall
- Add port 5432 for TCP
- Apply the changes
Verify PostgreSQL is listening:
ss -tulpn | grep 5432You should see PostgreSQL listening on 0.0.0.0:5432 and [::]:5432
Step 10: Install pgAdmin 4
Add pgAdmin Repository
dnf install -y https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-2-1.noarch.rpmInstall pgAdmin 4 Web
dnf install -y pgadmin4-webThis will install pgAdmin along with Apache (httpd) as a dependency.
Setup pgAdmin
Run the setup script:
/usr/pgadmin4/bin/setup-web.shWhen prompted:
- Enter your email address (e.g., [email protected])
- Set a strong password
- Type
yto 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
nano /etc/httpd/conf/httpd.confSearch for Listen 80 (press Ctrl+W) and change it to:
Listen 8081Save and exit.
Open Port 8081 in Firewall
In CyberPanel:
- Go to Security → Firewall
- Add port 8081 for TCP
- Apply changes
Start Apache
systemctl start httpd
systemctl enable httpd
systemctl status httpdVerify Apache is running on port 8081.
Step 12: Setup Custom Domain with LiteSpeed Reverse Proxy
Create Website in CyberPanel
- Log into CyberPanel
- Go to Websites → Create Website
- Enter:
- Domain: pgadmin.yourdomain.com
- Email: your email
- Select a package
- Click Create Website
Point DNS
Create an A record for pgadmin.yourdomain.com pointing to your server IP.
Configure LiteSpeed Reverse Proxy
- In CyberPanel, go to Websites → List Websites
- Find pgadmin.yourdomain.com and click Manage
- Click on “vHost Conf”
- Add this external processor configuration before the
phpIniOverridesection:
extprocessor pgadmin_proxy {
type proxy
address http://127.0.0.1:8081
maxConns 100
pcKeepAliveTimeout 60
initTimeout 60
retryTimeout 0
respBuffer 0
}- Add this context configuration after the existing
context /block:
context /{
type proxy
handler pgadmin_proxy
addDefaultCharset off
}- Save the configuration
- Restart LiteSpeed:
systemctl restart lswsStep 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
nano /etc/httpd/conf.d/pgadmin4.confChange this line:
WSGIScriptAlias /pgadmin4 /usr/pgadmin4/web/pgAdmin4.wsgiTo:
WSGIScriptAlias / /usr/pgadmin4/web/pgAdmin4.wsgiSave and exit, then restart Apache:
systemctl restart httpdStep 14: Access pgAdmin
Open your browser and navigate to:
https://pgadmin.yourdomain.comLog in with the email and password you set during pgAdmin setup.
Step 15: Connect PostgreSQL to pgAdmin
- In pgAdmin, right-click “Servers” in the left sidebar
- Select Register → Server
- In the “General” tab:
- Name: Production PostgreSQL 18
- 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)
- Click Save
You should now see your PostgreSQL server connected in pgAdmin!
Security Best Practices
- Change Default Passwords: Always use strong, unique passwords
- Restrict Remote Access: If you don’t need remote database access, remove the
0.0.0.0/0rules from pg_hba.conf - Enable SSL: Configure PostgreSQL to use SSL for encrypted connections
- Regular Updates: Keep PostgreSQL and pgAdmin updated
- Firewall Rules: Only open necessary ports and restrict access by IP when possible
- 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:
systemctl status postgresql-18View PostgreSQL logs:
tail -f /var/lib/pgsql/18/data/log/postgresql-*.logCheck Apache status:
systemctl status httpdCheck listening ports:
ss -tulpn | grep -E '5432|8081'Restart services:
systemctl restart postgresql-18
systemctl restart httpd
systemctl restart lswsConclusion
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.


