How to Change Apache HTTP Port in Linux

The Apache HTTP Server is sometimes simply known as Apache. Apache, by default, listens on port 80 for incoming HTTP requests. But there is a need to change the default port which is necessary. Sometimes, we want to run numerous web servers on the same system or we want to improve the security by relocating Apache to an uncommon port.

Let us discuss how to change the Apache HTTP default port in a Linux system in this article.

Why We Should Change the Apache HTTP Port

The following are some factors to change our default Apache HTTP Port:

  • Changing the default Apache HTTP port offers one more security so that the hackers cannot find the web server.
  • This helps to avoid conflicts with other services or apps that may be utilizing the default port, resulting in smoother server functioning.
  • Changing the port allows us to configure our server to meet our individual needs such as running many web servers on the same machine.

Installation of Apache in Linux

Before we begin changing the Apache HTTP port, we must first check that Apache is installed on our Linux system. We can use the following command to install Apache in our Linux operating system:

$ sudo apt install apache2

The command downloads and installs Apache from the repository. The “systemctl” command is used to control the system services and it allows us to start, stop, and check the status of Apache. Here is the command to start the Apache server daemon:

$ sudo systemctl start apache2

This command starts the Apache service, and our web server is now operational. Now that we installed Apache, we can change the default HTTP port to fit our needs better.

Steps to Change the Apache HTTP Port in Linux

We can easily modify our default Apache HTTP Port. We need to make changes to our Apache configuration files.

Here are the simple steps:

  • Stop the Apache Service: Before we make any change, we need to stop running the Apache server by executing the following command in our terminal:
$ sudo systemctl stop apache2
  • Change the Apache Port: We can use a text editor like Nano or Vim to open the “ports.conf” file. We can type the following command to open this file:
$ sudo nano /etc/apache2/ports.conf


Listen 80

<IfModule ssl_module>

Listen 443


<IfModule mod_gnutls.c>

Listen 443


** many more outputs **

After that, we need to search for the line that says “Listen 80” and replace “80” with any desired custom port. Let us change it to “Listen 88”.

  • Change the Virtual Host Configuration File: We must also change the virtual host configuration file in the Linux operating system. Let us use any text editor to open the configuration file.
$ sudo nano /etc/apache2/sites-enabled/000-default.conf


<VirtualHost *:80>

** many more outputs **

We need to search for the “<VirtualHost *:80>” line in the file and replace “80” with a custom port. Let us change it to “<VirtualHost *:88>”.

Restart Our Apache and Verify the New Port

After changing the port, we must restart the Apache HTTP server. The following command needs to be used to restart:

$ sudo systemctl restart apache2

We can verify the changes using the “netstat –tlpn” command.

$ sudo netstat -tlpn | grep apache


tcp6 0 0 :::88 :::* LISTEN 4956/apache2

The command allows us to check the status of our Apache server. It displays a list of sockets associated with our Apache server and ensures that it is running on the port that we have chosen.


Finally, changing the default Apache HTTP port in Linux offers us with increased security, avoids conflicts, and allows for customization. By understanding these simple steps, we can change our Apache HTTP port to better suit our needs.

Similar Posts