21+ years in hosting · Jaipur, India · INR billing with 18% GST · 24/7 email support
Blog · WebJi® India

How to Find Your Database Hostname in cPanel

Quick answer

On a cPanel account the database hostname is localhost, because MySQL runs on the same server as the site. Server Information shows the Server Name for remote-database cases. Enter localhost in wp-config.php or .env; a refused connection means the value is wrong.

For WordPress and Laravel users on cPanel who keep hunting for the database host: where it lives, how to confirm it, and how to read the errors.

✓ In business since 2005
✓ INR + GST billing
✓ 24/7 Email Support — avg reply < 60 min
GuideWebJi®
knowledge
Read time
4 min
Sections
6
Updated
14 Nov 2026
Written by
WebJi® team

What exactly is the database hostname?

The database hostname is the address an application uses to reach the MySQL server — and on a cPanel account that address is localhost, because MySQL runs on the same machine as your site. It is one of four strings a config file needs, and it is the one people most often confuse with the others.

  • Database host: where the MySQL server lives — localhost on cPanel.
  • Database name: what you created in MySQL Databases, prefixed with your cPanel username.
  • Database user: also prefixed, and granted access to that one database.
  • Password: the user's password, not your cPanel login password.

It is not your domain name, not the cPanel login URL, and not the shared IP address. Mixing those up produces the classic "error establishing a database connection" that sends people hunting through the panel.

How do you read the database host from inside cPanel?

Open cPanel for the account, read the General Information panel on the home screen, then open Server Information — the Server Name row is the machine's hostname, which you only need when the database sits on a different server. Log in to cPanel itself, not the billing area; the billing login does not show server details.

  1. Find General Information. On the cPanel home screen it sits in the right-hand column and shows the shared IP address.
  2. Click Server Information. The Server Name row prints the machine's hostname, for example server42.
  3. Write localhost in your app config when site and database share the account. Reserve the Server Name for connections from outside the server.

One place it will not appear is the MySQL Databases page. That page lists your databases and users but does not print the host, which is exactly why people search there, find nothing, and assume the value is hidden. On a cPanel server the convention is simply localhost. WebJi® sells cPanel hosting as a separate product from its Linux shared plans — ₹297 a month before 18% GST for 20 GB disk, 200 GB bandwidth, 10 email IDs and 1 domain — and it follows the same localhost convention.

Can you confirm the host from the terminal?

Yes — if cPanel Terminal or SSH is enabled, four quick commands confirm what the panel reports, and one mysql command proves the connection before you redeploy anything. Run them on the server itself, not on your laptop, or you will be inspecting the wrong machine.

Commands that confirm the server identity on a cPanel box
CommandWhat the output tells you
hostnameThe short server name, for example server42
hostname -fThe fully qualified name, for example server42.webji.services
host server42.webji.servicesThe name resolved to its IP address
dig +short server42.webji.servicesJust the IP address, for example 203.0.113.10

The example names above are illustrations; your server answers with its own. Then test the database login itself:

mysql -h localhost -u cpuser_wp -p cpuser_wp -e "SELECT 1;"

A one-row table containing 1 means the host, user and password all agree. Any error message that prints names the exact thing to fix before WordPress or Laravel ever sees it. On the server, MySQL still answers at localhost — the hostname matters only for a client connecting from outside, which is the case below.

Where does the hostname go in wp-config.php and .env?

WordPress reads the host from DB_HOST in wp-config.php, next to DB_NAME, DB_USER and DB_PASSWORD; Laravel reads the same key as DB_HOST in .env — and on cPanel both take localhost.

// wp-config.php
define( 'DB_NAME', 'cpuser_wp' );
define( 'DB_USER', 'cpuser_wp' );
define( 'DB_PASSWORD', '••••••••' );
define( 'DB_HOST', 'localhost' );

Edit the file through cPanel File Manager or over SFTP, save, and reload the site. If the old value keeps coming back on a Laravel app, a cached config is hiding your edit — clear it with php artisan config:clear and reload again.

One subtlety worth knowing: MySQL grants are per host. A user created as 'cpuser_wp'@'localhost' connects through the local socket and can be refused at 127.0.0.1, because that form goes over TCP. If localhost works and 127.0.0.1 does not, the string is not the problem — the grant is.

What does a wrong database hostname look like?

The error text tells you whether the host or the credentials are at fault, so read it before changing either — a wrong host never produces "access denied". That message proves the connection arrived and was refused on identity; leave DB_HOST alone and fix the user or password.

Common database connection errors and what each one means
MessageWhat it means
Error establishing a database connectionWordPress cannot connect. Check DB_HOST first, then the user and password.
SQLSTATE[HY000] [2002] Connection refusedNothing listens at that address and port — the host value is wrong or the server is down.
Unknown MySQL server hostDNS cannot resolve the name. Fix the spelling or use localhost.
Can't connect through socketThe client expected a local socket; the database is remote, so use its hostname.
Access denied for user (using password: YES)The host was reached. The username or password is wrong, not the host.

What changes when the database is on another server?

A remote database needs two changes: add the connecting server's IP as an access host in cPanel's Remote MySQL page, and set DB_HOST to the database server's hostname instead of localhost. Skip either half and the connection fails, no matter how correct the password is.

Many shared platforms also block port 3306 from outside the network as a safety measure. If the access host is set correctly and the connection still times out, the port is closed — that is a question for support, not a config edit. WebJi® answers support@webji.services 24/7 in Hindi and English, with an average first reply under 60 minutes.

Keep DNS out of the diagnosis. A database error is not a domain resolution problem; the cPanel nameserver guide matters only when the site itself will not load, and the domain IP lookup shows what a name resolves to. For the panel itself — plans, backups, email — see cPanel hosting and the cPanel full backup guide.

FAQ

Frequently asked questions

Is the database host always localhost?

For MySQL running on the same cPanel server as the site, yes — localhost is the convention cPanel is built around. It stops being localhost when the application talks to a remote database server, a managed database service, or a second machine you run yourself.

Why doesn't the MySQL Databases page show the hostname?

Because the panel assumes the local default. MySQL Databases lists databases, users and grants, not the host. The Server Information page carries the machine's Server Name, and that value is only needed for remote connections.

What does SQLSTATE error 2002 mean?

Connection refused: the client could not reach a MySQL server at the address and port it was given. The host value is wrong, the server is down, or a remote connection is being blocked. It is not a password problem — that reports access denied instead.

Do localhost and 127.0.0.1 behave the same in DB_HOST?

Usually, but not always. MySQL treats localhost as a unix-socket connection on Linux and 127.0.0.1 as TCP, and grants are granted per host. If one works and the other is refused, the user's grant table needs the matching host form — the string itself is fine.

Last editorial update: 15 November 2026.

WebJi® since 2005

Ready to get started with WebJi®?

Join 12,000+ businesses across India and overseas. INR pricing, 18% GST shown before payment and 24/7 email support in Hindi and English — average first reply under 60 minutes.