How to configure Apache Server to listen on a Custom port?

Where necessary, you may need to have access to a VPS server so you can follow how to implement the steps in this article.  You can get a cheaper VPS Server from Contabo with 4vCPU cores, 8GM RAM, and 32TB Bandwidth for less than $5.50 per month. Get this deal here now

Table of Contents

Cloud VPS S

$5.50 Monthly
  • 4 vCPU Cores | 8GB RAM


$15.50 Monthly
  • 6 vCPU Cores | 16GB RAM


$17.50 Monthly
  • 8 vCPU Cores | 24GB RAM

To configure Apache to listen on a custom port, you’ll need to make changes to its configuration files. Here are the steps:

Backup Configuration Files

Creating a backup copy of your Apache configuration file is a good practice before making any changes. Here’s how you can do it:

On Linux/Unix Systems

Use a command-line text editor like cp (copy) or cp with sudo to create a backup:

sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_backup

Replace /etc/apache2/apache2.conf with the actual path to your Apache configuration file.

On Windows

Navigate to the directory where your Apache configuration file is located. Use the copy command to create a backup:

copy httpd.conf httpd_backup.conf

Replace httpd.conf with the actual name of your Apache configuration file.

After creating the backup, you’ll have a copy of the configuration file with the “_backup” suffix. You can use this backup to restore the configuration if needed, especially should anything go wrong.

Open the Apache Configuration File

Open the Apache configuration file in a text editor. The location of the configuration file can vary depending on your operating system and installation method. Common locations are:

  • For CentOS/RHEL Linux systems
nano /etc/httpd/httpd.conf 
  • For Ubuntu/Debian Linux systems
nano /etc/apache2/apache2.conf
  • For Windows Operating Systems
 C:\Program Files\Apache Group\Apache2\conf\httpd.conf

Below is the sample Apache configuration file:

ServerRoot "/etc/apache2"

Listen 80

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted

# ...

IncludeOptional sites-enabled/*.conf

Find the “Listen” Directive

In the Apache configuration file, look for a line that starts with the “Listen” directive. This directive specifies the port on which Apache listens for incoming connections.

   Listen 80

Change the Port

Change the port number to your desired custom port. For example, if you want Apache to listen on port 8080:

   Listen 8080

Update Virtual Hosts (Optional)

If you have virtual hosts configured, you also need to update their configurations to reflect the new port. Look for <VirtualHost> sections in your configuration file and update the VirtualHost directive with the new port.

   <VirtualHost *:8080>
      # Virtual host configuration

Save the changes to the configuration file and close the text editor.

Restart Apache

After making changes, you need to restart the Apache server for the changes to take effect. The command to restart Apache varies by operating system:

sudo service apache2 restart 


sudo systemctl restart apache2

Now, Apache should be listening on the custom port you specified. Access your web server by navigating to (replace with your actual domain or IP address and 8080 with your custom port).

Hire us to handle what you want

Hire us through our Fiverr Profile and leave all the complicated & technical stuff to us. Here are some of the things we can do for you:

  • Website migration, troubleshooting, and maintenance.
  • Server & application deployment, scaling, troubleshooting, and maintenance
  • Deployment of Kubernetes, Docker, Cloudron, Ant Media, Apache, Nginx,  OpenVPN, cPanel, WHMCS, WordPress, and more
  • Everything you need on AWS, IBM Cloud, GCP, Azure, Oracle Cloud, Alibaba Cloud, Linode, Contabo, DigitalOcean, Ionos, Vultr, GoDaddy, HostGator, Namecheap, DreamHost, and more.

We will design, configure, deploy, or troubleshoot anything you want. Starting from $10, we will get your job done in the shortest time possible. Your payment is safe with Fiverr as we will only be paid once your project is completed.