PostgreSQL runs on our servers, cPanel carries its tools, and a PHP website can talk to it. There are two things to know before you start, and neither is obvious: the PHP driver arrives switched off and you switch it on in a panel screen, and from outside you do not connect directly, you come in through a tunnel. This article covers both.
What exists, and in what state
| Piece |
Status |
| The PostgreSQL service |
It exists and it is running. |
| Creating databases and users |
In cPanel, on the PostgreSQL databases screen. It works like the MySQL one: a database, a user, and the link between them. |
| A browser tool |
phpPgAdmin, also in cPanel. It is the phpMyAdmin equivalent. |
| The driver in the site’s PHP |
It exists, but it arrives switched off. It is in the extension list on Select PHP Version, with a tick box. See the next section. |
| A direct connection from the internet to the database port |
No. The service only answers inside the machine itself, and the port is not open to the outside. |
| An allowed-addresses list, like MySQL has |
There is none on the PostgreSQL screen. It is not hidden; it does not exist. |
Switching the driver on, so your PHP site can talk to it
If what you want is a PHP application reading and writing to the database, this is the step, and it takes about two minutes. You do not have to ask us for anything.
| 1 |
In cPanel, open Select PHP Version, in the software section.
|
|
| 2 |
Check the chosen PHP version first. Extensions are switched on per version: change version later and the list resets, and you have to tick it again. It is the number one cause of «it worked and then it stopped».
|
|
| 3 |
In the extension list, tick the PostgreSQL driver and save. There are usually two names in the list, one for the direct connection and one for the generic database access layer: if your application uses the generic layer, tick both.
|
|
|
If your project is still undecided, think twice. Everything around a website here, from backups to tooling, was designed around MySQL, which is what the overwhelming majority use. PostgreSQL works; it simply has less safety net around it. If there is no concrete reason to choose it, MySQL will give you less work.
|
Reaching the database from outside: the SSH tunnel
For pgAdmin, DBeaver or psql on your own computer, a direct connection is no good, because the database only answers inside the machine. An SSH tunnel solves it: it connects to the machine on the SSH port, which here is 2299, and makes a port on your computer point at the database in there.
| 1 |
Check that your account has SSH. In cPanel, look for Terminal or SSH Access. If neither is there, your plan has no shell switched on and you need to ask us.
|
|
| 2 |
Create the database and the user in cPanel, and attach one to the other. Without that link the user logs in and sees nothing.
|
|
| 3 |
Open the tunnel from your own computer: ssh -p 2299 -L 5433:localhost:5432 user@server . Leave the window open: the tunnel lives as long as it does.
|
|
| 4 |
Point the tool at your own computer. Host 127.0.0.1 and port 5433. The user and password are the database ones you made in cPanel.
|
|
|
There is nothing special about 5433. It is just a free port on your computer, picked so it does not clash with a PostgreSQL you may have locally. If you have none, use 5432 on both sides. The number on the left is yours; the one on the right is the server’s.
|
pgAdmin can also build the tunnel itself, on the SSH tab of the connection. It is tidier and saves you the open window. Same fields: host, port 2299, cPanel user.
|
Do not retry failed SSH logins. The firewall counts failures and after a few locks out the address they came from, which also cuts off your website and your e-mail. Two wrong attempts and you stop and check the details. Already locked out: how to unblock your IP address.
|
What if I only want to look something up?
Then you do not need a tunnel at all. Log in over SSH and use psql in there; it is installed and visible from your account. For a quick query or to run a script file it is the shortest route there is. And to look at tables without writing SQL, phpPgAdmin does the job with nothing to install.
Backups: confirm, do not assume
The account backups were designed around what most sites actually use. If you have put real data into a PostgreSQL database, export it yourself as well, regularly, and keep the export off the server. The habit is in making and keeping your own backup. And check with us what is actually being copied before you rely on it.
|
Got a project that needs PostgreSQL and want to confirm it fits here? Tell us what it does.
Open a support ticket
|
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from $9.99/mo See plans |