What is localhost:8080?
Everything connected to the internet can be found using a socket address. Socket Addresses are a combination of IP addresses (or simply hostname) and port numbers. Socket Addresses are used to identify both machine and the service within the machine. If we consider localhost:8080 then here localhost is hostname which is bound to IP address ie. 127.0.0.1 by default and 8080 is the port. Here, localhost means this computer ie. the computer which you are using right now.
Ip address is just like house address which finds the right house. Similarly, Ip finds a particular system in a network.
Port is the person number. Person number which finds an actual person on that house. Similarly, Post used to identify the process that needs to consume the packet.
In localhost:8080, localhost is DNS hostname which is pointing to localhost IP address ie. 127.0.0.1. If you type ping localhost in terminal or command prompt, you will find that your machine automatically points localhost to IP addresses such as :1 or 127.0.0.1. Actually, 127.0.0.1 is the IPV4 address and::1 is the IPV4 address of localhost.So typing localhost:8080 or 127:0:0:1::8080 are same things. Here 127:0:0:1 is a private Ip address that is not recognizable by another computer in the network. It is recognized by this machine only.
Generally while building the application locally by the web developer, they develop the web application and the default socket will be localhost:8080. This is the default port that the webserver XAMP, WAMP, LAMP server uses for developing and testing the application.8080 is just a random port someone sets in different web servers for testing and development and you can change it if you want.
But note that no two applications or processes can use the same port. ie. two applications running cannot run on port 8080 at the same time. If one process is using 8080 then if another application tries to access 8080 then it will give you a message like "port is already in used" please use another port.
If you are running a .net application or PHP application and when you are debugging that application it will have localhost:8080 upon running in the browser URL by default. The webserver will not search the information on the internet but will search pages in a local hard drive it will search for the webpage by local webserver at port 8080 from the local hard drive
If you are using a windows machine, then the IIS server is enabled then just typing localhost will redirect you to C:/inetpub/wwwroot/iisstart.htm files. Here the port by default is 80. Considering C drive is your OS drive.
Similarly, if you use the XAMP server then typing localhost will just find the content like index.html or index.php present in htdocs folder.
What is 8080 port?
It is to be noted that there is a total of 65,535 ports for communication between the devices where 0-1023 are well-known reserved ports you cannot assign IP to this. Port 1024 to 49151 are user ports and users can assign applications to them. And port above 49151 is a private port. So, port 8080 is the user registered port. In our case by default XAMP or WAMP server assign for the application.
If you have a web server already running on default port 80 and you like to host another web server on the HTTP service then the webserver will automatically host you to port 8080 which is a best practice followed by most of the web servers and if that port is also in use then may assign any user port like 8081,8082 etc
You can change it, the only thing you have to keep in mind is that you cannot assign an already used port otherwise it will give an error as we have mentioned earlier
8080 must be explicitly specified for HTTP as 80 will be assumed by most browsers. But some web server like Angular, Rails server uses 8000, 4200 as the default port
What exactly is going on When I type localhost:8080?
Ans: When you type localhost:8080, this will make your web browser ask your operating system to do a DNS lookup and resolve the hostname as localhost.
The operating system looks at the files for DNS lookup.
In the windows system, the DNS mapping is located inside the hosts file located inside %systemroot%\System32\Drivers\Etc path and the hosts file look like this:
In Unix systems like Linux, the DNS mapping are stored inside /etc/hosts file, and look like this:
So when you hit localhost:8080 the browser then the webserver finally gets the result from the 127.0.0.0:8080 location and displays the result in the browser.
Ans: Yes both localhost:8080 and 127.0.0.1:8080 point to the same IP address on TCP port 8080.
Sometimes port 80 is already in use; in this case, try using the 8080 port in Xamp. Let's look at how to change it.
- Open xampp
- Right-click on the Config button for Apache.
- Click on Apache(httpd.conf) file.
- Find Listening port and change the port from 80 to 8080.
ie Listen 80 to Listen 8080
- Also, change ServerName from localhost:80 to ServerName localhost:8080
- Then save the file and after that restart Xamp and by default, your Apache server will run on port 8080
When you run a web server on your local computer, you will have to connect a web application with the web server and port 80 is already in use, so you will need to use a new port. So, most of the webserver usage available port 8080 to connect application which is currently running. If port 8080 is already in use by some other process then the web server may assign 8081 for the application.