Alexander Mills
Alexander Mills

Reputation: 100010

Why is a port necessary for running a server or database locally?

Can someone explain why using a port is necessary when running things locally? I assume the reason is because the same software could be run remotely and in that case specifying a port would be necessary. When a database or server is running locally, do requests from a locally running web browser really "go through the port" specified?

Upvotes: 1

Views: 1487

Answers (2)

Alejo_Blue
Alejo_Blue

Reputation: 615

Sometimes You may have some other software installed in your computer that may use the same port. For instance Apache and IIS: imagine you set port 8080 to IIS as default, what about if you had previously installed Apache set port 8080 ?

Another example will be if you installed Mysql Workbench and days later install XAMPP you may have trouble with the ports if you don't change one instance's port different from 3306

This is why it is necessary to specify ports even though is locally.

Upvotes: 1

nneonneo
nneonneo

Reputation: 179422

Good question. In fact, there are local-only communication protocols, such as pipes and UNIX domain sockets that do not actually require port numbers to operate. This is because they refer to files or other identifiers that are only valid on the computer itself.

However, most servers are designed for TCP/IP connections. TCP/IP itself specifies a port number in the protocol. It is normally intended for remote use, but when a server that is used to TCP/IP runs "on local host", it must supply a port number to satisfy the TCP protocol.

Port numbers also enable multiple servers to coexist on a single computer, all running on different ports. For a protocol without port numbers, this is achieved by using different identifiers (e.g. a filesystem file) for each server.

Some servers can operate on both TCP/IP and local sockets. For example, MySQL can accept connections both through the usual TCP port, and also through a local socket (mysql.sock). Connecting through the local socket is reserved for local users only, and may be faster on some systems.

Upvotes: 5

Related Questions