How to Change Apache port in Ubuntu Server 16.04

By default Apache web server run on port 80, which is port use by the HTTP protocol. But sometimes you will need to change the default apache port to a different port, for example, if you are planning to run more the one web server on your Ubuntu Server 16.04.

In this tutorial we are going to learn how to change the default apache port number in Ubuntu Server 16.04.

In Ubuntu Server, Apache port is defined in /etc/apache2/ports.conf file. So first open the /etc/apache2/ports.conf file using a text editor.

vim /etc/apache2/ports.conf

locate the line that reads Listen 80 and change the value 80 to your new port number. For example, if you want to change apache port to 8080,

Listen 8080

Change Apache port in Ubuntu Server 16.04

Then save the configuration file and restart the Ubuntu Apache web server.

service apache2 restart

Since we changed the default port, we also need to configure Apache virtual hosts to listen to the new port number.

<VirtualHost *:8080>

ServerName www.example.com

</VirtualHost>

Visitors to your web site must specify the new port number in the URL when they access the website. For example, if the website name is www.exmaple.com and the port number is 8080, then the URL should access as,

http://example.com:8080

Configure Multiple Port numbers

It is also possible to configure apache web server to listen on Multiple port numbers by adding multiple Listen ports to the /etc/apache2/ports.conf.

Listen 80

Listen 8080

Configure Multiple Port ubuntu apache

As per the above configuration, Apache server now Listen to the both TCP ports 80 and 8080 on Ubuntu Server 16.04.