This kind of connection is called loopback: data goes out and comes straight back to the same machine. So the meaning depends on where the code runs. localhost on your laptop is your laptop; localhost in code running on a server is that server.
Where you’ll see it
- Local development: run a project on your computer and open it at something like
http://localhost:3000, where 3000 is the port. - Database settings: when MySQL runs on the same server, wp-config.php says:
define( 'DB_HOST', 'localhost' );
or, in a Laravel .env file:
DB_HOST=localhost
- The hosts file: the name-to-address mapping lives in
/etc/hostson Linux and macOS, and inC:\Windows\System32\drivers\etc\hostson Windows.
localhost or 127.0.0.1?
Usually it makes no difference, but MySQL and MariaDB on Linux tell them apart: localhost connects through a local socket file, while 127.0.0.1 connects over TCP on port 3306. If you see Can’t connect to local MySQL server through socket, try the other value. Sometimes localhost also resolves to the IPv6 ::1 while the service only listens on IPv4, and the connection is refused.
Common mistakes
- An app listening only on localhost: nothing outside the machine can reach it, which is usually intentional for security, as with databases and Redis.
- localhost links left after a move: build a site on your laptop, upload it, and image and page URLs may still say
localhostin the database, so visitors see an unstyled page. - A changed database host: after moving to another host, check
DB_HOSTif you get Error establishing a database connection.
On ArabyHost
MySQL/MariaDB databases run on your account’s own server, so DB_HOST is localhost in WordPress, Laravel and similar apps. On the Developer plans, keep connection details in environment variables or a .env file rather than in your code, and if a connection error appears, the Araby AI assistant reads the error log and explains the cause and the fix.
FAQ
Why does my database host say localhost instead of the server's address?
Because the database usually runs on the same server as your site. Connecting through localhost is faster and safer because the traffic never leaves the machine.
I sent a friend a localhost link and it didn't open. Why?
On their computer, localhost means their computer, not yours. To share a project, put it on hosting or use an address that's reachable from the internet.
Are localhost and 127.0.0.1 the same thing?
In most software, yes. MySQL and MariaDB on Linux treat them differently: localhost means a local socket file, while 127.0.0.1 means a TCP connection.