## Port

Syntax: Port number
Default: `Port 80`
Context: server config
Status: core

Number is a number from 0 to 65535; some port numbers (especially below 1024) are reserved for particular protocols. See `/etc/services` for a list of some defined ports; the standard port for the http protocol is 80.

The Port directive has two behaviors, the first of which is necessary for NCSA backwards compatibility (and which is confusing in the context of Apache).

- In the absence of any Listen or BindAddress directives specifying a port number, a Port directive given in the "main server" (i.e., outside any <VirtualHost> section) sets the network port on which the server listens. If there are any Listen or BindAddress directives specifying `:number` then Port has no effect on what address the server listens at.
- The Port directive sets the `SERVER_PORT` environment variable (for CGI and SSI), and is used when the server must generate a URL that refers to itself (for example when creating an external redirect to itself). This behaviour is modified by UseCanonicalName.

In no event does a Port setting affect what ports a VirtualHost responds on, the VirtualHost directive itself is used for that.

The primary behaviour of Port should be considered to be similar to that of the ServerName directive. The ServerName and Port together specify what you consider to be the canonical address of the server. (See also UseCanonicalName.)

Port 80 is one of Unix's special ports. All ports numbered below 1024 are reserved for system use, i.e., regular (non-root) users cannot make use of them; instead they can only use higher port numbers. To use port 80, you must start the server from the root account. After binding to the port and before accepting requests, Apache will change to a low privileged user as set by the User directive.

If you cannot use port 80, choose any other unused port. Non-root users will have to choose a port number higher than 1023, such as 8000.

SECURITY: if you do start the server as root, be sure not to set User to root. If you run the server as root whilst handling connections, your site may be open to a major security attack.