I installed easyPHP and opened a port on my firewall so that other people can access to my webserver. The default port is 8888. But I am wondering how do you choose a port number? Is it really ambiguous or there is a "prefered" range of port number?
-
@JakeGould Thanks for your comment it really helped me.!– GeneCodeCommented Jul 24, 2018 at 2:56
-
Possibly related question: stackoverflow.com/questions/10476987/…– glennerooCommented Jul 24, 2018 at 18:48
-
1Does this answer your question? Can I serve a website on any port I want to?– Jim G.Commented Oct 19, 2022 at 14:33
1 Answer
A port number is a 16-bit unsigned integer, thus ranging from 0 to 65535 (although 0 cannot be used for TCP; it has a special meaning for UDP).
You can use pretty much any port number in the range, however there are some guiding rules:
- (On Unix based systems at least), only root can bind to ports below 1024.
- You ideally don't want a port typically associated with another common service as this can cause problems with some firewalls.
- Expanding on (2) above - On Linux systems at least, there is a file
/etc/services
which has a list of common services - you can use this for guidance.
The "ideal" port to run an HTTP service is port 80, and the ideal port for HTTPS is 443, because those ports are associated with their respective services. If this is not practical (and it often isn't - some routers are too stupid to handle a web interface and port forward externally on the same port), it's common to pick a "themed" port - port 8080 is pretty common, as is port 8000.
-
1On modern Windows versions you have to have administrator privileges in order to bind to ports below 1024 as well. Commented Jul 24, 2018 at 9:54
-
@enkryptor: Which versions are those? Is this documented anywhere? Commented Jul 24, 2018 at 13:25
-
@grawity I believe it's Windows 7 and later. You can also give a permission to a non-admin user for a specific url via
netsh http add urlacl
Commented Jul 24, 2018 at 13:31 -
@enkryptor I have nginx running on port 80, non-localhost ip, and I'm not admin in this system.– BraiamCommented Jul 24, 2018 at 13:52
-