How To Change Apache HTTP Port in Linux

In this tutorial, we will guide you through the process of changing an HTTP port in Linux Apache.
Apache HTTP is a widely used web server that offers a plethora of features, including flexibility and stability. By default, the Apache web server listens to incoming connections and links to port 80 of the computer. If a TLS configuration is used, the server will listen for secure connections on port 443.
However, if you want the Apache web server to listen to web traffic on other ports besides the standard web ports, you will need to add a new instruction that includes the new listening port. This process is crucial for those who want to customize their web server to fit their specific needs. With our step-by-step instructions, you'll be able to easily modify your Apache server and enhance its functionality.
Modify HTTP Port of Apache Server
In distributions based on Debian or Ubuntu, the configuration file to edit is the file /etc/apache2/ports.conf and in the distributions based on RHEL or CentOS we will edit the file /etc/httpd/conf/httpd.conf.
nano /etc/apache2/ports.conf (Debian/Ubuntu) nano /etc/httpd/conf/httpd.conf (RHEL/CentOS)
For this case, we will use Ubuntu 17. When accessing this file, we will see the following:
As we can see, the default value in the line LISTEN is port 80.
For this tutorial, we will configure the Apache HTTP server so that it listens to the connections in port 8081 of the devices.
Therefore, we will add the line “LISTEN 8081” just under the port 80 line:
Save the changes using the following key combination Ctrl + O and exit the editor using Ctrl + X.
Once you have successfully added the new instruction for the Apache web server to listen to web traffic on a new port, the next step is to create or modify a virtual Apache host. This is a necessary step for those using Debian or Ubuntu distributions, as it will initiate the link process and cater to the vhost requirements. On the other hand, if you are using CentOS or RHEL distributions, the change can be applied directly to the default virtual host.
To modify the port in CentOS or RHEL, you need to open and edit the 000-default.conf file. Within this file, you can change the port number to your desired value, such as 8081. This modification will ensure that incoming connections are linked to the correct port, allowing your web server to function optimally.
In summary, changing the HTTP port in Linux Apache is a simple but essential process that can enhance your web server's functionality. By following our step-by-step instructions and modifying your virtual Apache host or default virtual host, you'll be able to customize your web server to fit your specific needs and ensure that it operates at peak performance.
nano /etc/apache2/sites-enabled/000-default.conf
We set port 8081 on the “VirtualHost” line, save the changes and exit the editor.
Finally, we are going to apply the changes and allow Apache to link with the new port, for this we will restart the daemon and verify the local network socket table using the netstat or ss command.
Port 8081 to listen to should be displayed in the server network table as defined above; we will execute the following:
systemctl restart apache2 netstat -tlpn| grep apache ss -tlpn| grep apache
Now, to verify that the connection is correct, we will access from a browser using the following syntax:
http://IP_address:8081
In CentOS / RHEL-based Linux distributions, we are going to install the policycoreutils package to add the required SELinux rules so that Apache can link to the new port and restart the Apache HTTP server to apply the changes. We execute the following:
yum install policycoreutils
There we enter the letter and to confirm the download and installation. Then, we will add the SELinux rules for port 8081:
semanage port -a -t http_port_t -p tcp 8081 semanage port -m -t http_port_t -p tcp 8081
Now, we proceed to reset the Apache service:
systemctl restart httpd.service
Then, we will execute the command netstat or ss to verify if the new port joins correctly and listens to the incoming traffic, we will run some of the following lines:
netstat -tlpn| grep httpd ss -tlpn| grep httpd
Like Ubuntu, we can go to the browser and enter using the following syntax:
http://IP_address:8081
With this method, we can modify the default port of Apache in Linux.
It might be interesting
Ordering advertising from Influencers - a guide to finding and choosing
Influencer marketing in 2021 is recognized as one of the most effective ways to promote online. According to a study by Insider Intelligence, by 2022 brands will spend $15 billion on collaboration with opinion leaders.
In UK, blogging is on increase
In UK, blogging is really hitting the big time. According to some statistic in a week time, one out of every 84 website visits is for a weblog.
Hackers aiming at mobile phones
Mobile phone are becoming more like tiny computers with every passing day and some researchers says that the time is near when hackers will get their dirty paws all your messaging and other private stuff.
MediaTek was the first to show Wi-Fi 7 technology in operation
Wi-Fi 7-enabled devices are expected to hit the market in 2023