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:


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:


With this method, we can modify the default port of Apache in Linux.

It might be interesting

WIN! A PS3 Slim and Batman: Arkham Asylum

It is official; Sony is finally launching its latest PS3 slim edition next month at the GamesCom event in Cologne and you can win this year’s favourite Christmas present before anyone else on TechRadar.

Multimedia Assets and their Management

Various online businesses have been looking for some really smart tools and management systems to get complete command of their multimedia assets with better archiving and sharing of multimedia content.

Intel introduced Arc mobile graphics cards

Electronic devices and computer components manufacturer Intel has announced Intel Arc Mobile GPUs. Three families are presented - Arc 3, 5 and 7. All of them support XeSS scaling technology.

Cloud Computing Pros and Cons

The internet is responsible for changing the way we do many things, from shopping, to transferring money between bank accounts, advertising our own products or services, doing business 24 hours a day, finding a date, communicating on a personal or business level or getting the latest information on anything we’re interested in.