The Apache HTTP server is one of the internet’s most popular web servers today, thanks to its versatility, consistency, and a plethora of features, some of which are actually not available on other web servers, such as Nginx’s competitor. Some of Apache’s most significant features include the ability to load and run various types of modules and special configurations at runtime, without actually stopping the server or, worse, compiling the program whenever most of the new module is installed, and the special role played by .htaccess files that can modify web server configurations specific to webroot directories.
- By default, the Apache webserver is instructed to listen and bind on port 80.0 for incoming connections. If you opt for a TLS setup, the server listens on port 443 for stable connections.
- You need to add a new statement containing the new port for future bindings in order to instruct the Apache webserver to connect and listen to web traffic on ports other than normal web ports.
- The configuration file that needs to be changed on a Debian/Ubuntu-based device is /etc/apache2/ports.conf and update /etc/httpd/conf/httpd.conf on RHEL/CentOS-based distributions.
With a console text editor, open a file unique to your own distribution and add a new port comment, as seen in the excerpt below.
nano /etc/apache2/ports.conf [On Debian/Ubuntu]
In this example, the Apache HTTP server will be configured to listen to the connections on port 8081. Make sure that you apply the statement below to this file after the directive instructing the webserver to listen on port 80, as seen in the image below.
After you have added the above line, to start the binding method, unique to your own vhost requirements, you need to build or change an Apache virtual host in the Debian/Ubuntu-based distribution.
Finally, to implement the changes and connect Apache to a new port, restart the daemon.
# systemctl restart apache2
Then use the netstat or ss command to search the local network sockets table.
# netstat -tlpn| grep apache
# ss -tlpn| grep apache
You can also open a window and navigate to the IP address or domain name on port 8081 of your computer. The default Apache page in the browser should be shown. If you are unable to access the webpage, however, go back to the server console and make sure that the correct firewall rules are configured to allow port traffic.