If port 80 is already taken
Last week, I encountered a server with its HTTPS port 80 already taken by another software. The “culprit” was unsurprisingly another web server software, namely IIS. Because the IIS users are already accustomed to the default port, the Apache installation had no choice but to use a less popular port for HTTP, in this case case port 81.
You might ask why is port 80 important for http? Well, for one, it is the ease of use for the users. If you are browsing to a web server listening on a port other than port 80, you will need to include the port number along with the address.
Something like this: http://yourdomain.com:81/ if port 81 is your web server’s port. If you use port 80 then you won’t have to type in port 80 on the address since it is the standard port used for HTTP. According to http://www.tcpipguide.com
“To avoid chaos, the software that implements a particular server process normally uses the same reserved port number on every IP device, so clients can find it easily… Every Web browser just “knows” that websites are designed to listen for requests sent to port 80”.
So having that fact settled, let’s see how we can change the port of our Apache setup. First look for the httpd.conf file inside the Apache > conf folder.
httpd.conf is a text file used by all Apache implementations, so changing a Unix Apache or Windows Apache install is done the same way – thru this config file. Open the file using your favorite text editor and look for the line with “Listen 80”:
This line defines Apache to listen on port 80. All you have to do is change that port 80 to any port that you want to use. Make sure that the port that you will use is a free port and not already taken by other services. Read our guide about a free port scanner if you are not sure.
Once you have edited the file, save it and restart Apache. To test if you already are using the new port browse the URL with the port you have used. For example, if you entered port 81 as the new port, the new URL should be http://yourdomain:81.
Another method that I read about online is slightly different. If the above doesn’t work for you, try going to /etc/apache2/ports.conf and changing the Listen line there to something like Listen 81.
Next, go to /etc/apache2/sites-enabled/000-default.conf and change the first line to VirtualHost *: 81. Restart Apache and you should be able to visit the domain without having to type in the port number. Apache should redirect automatically to /var/www/html. Enjoy!