How to Change an Apache Server Listening Port
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 tohttp://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 theApache>conffolder.
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 behttp://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.confand changing theListenline there to something likeListen 81.
Next, go to/etc/apache2/sites-enabled/000-default.confand change the first line toVirtualHost *: 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!
Founder of Help Desk Geek and managing editor. He began blogging in 2007 and quit his job in 2010 to blog full-time. He has over 15 years of industry experience in IT and holds several technical certifications.Read Aseem’s Full Bio
Welcome to Help Desk Geek- a blog full of tech tips from trusted tech experts. We have thousands of articles and guides to help you troubleshoot any issue. Our articles have been read over 150 million times since we launched in 2008.
HomeAbout UsEditorial StandardsContact UsTerms of Use
Copyright © 2008-2024 Help Desk Geek.com, LLC All Rights Reserved