How to Change Apache Port Number in Ubuntu


change port number in apache

By default, Apache listens to port 80 for serving HTTP requests. However, sometimes, you may have to make Apache listen to non-standard port number. For example, if you want your Apache to work behind proxy server, then it will not be able to use port 80, as port 80 will be used by the proxy server. In this case, you have to change Apache’s port number. Let us take a look at how to change Apache port number in Ubuntu.

 

 

How to Change Apache Port Number in Ubuntu

Here are the steps to change Apache Port Number in Ubuntu

 

1. Find the required configuration files

To change Apache’s port number, you need to make changes to 2 config files.

The first one is the global config file at /etc/apache2/port.conf where you update the global port number

Second, is located at /etc/apache2/site-available/

The 000-default.conf is configured to listen to port 80. default-ssl.conf is configured to listen to 443, in case, you want to change that port number too.

Here are the locations where you need to change the port number

 


$ sudo nano /etc/apache2/port.conf
$ sudo nano /etc/apache2/sites-available/000-default.conf
(Optional) $ sudo nano /etc/apache2/sites-available/default-ssl.conf

 

2. Change Apache Port Number

Now that we know which files to change, let us change the default port 80 to 8081

Open the port.conf file in a text editor


$ sudo nano /etc/apache2/port.conf

Look for the line


Listen 80

and change it to


Listen 8081

 

Save and close the file

 

Open Apache’s default site config file


$ sudo nano /etc/apache2/sites-available/000-default.conf

 

And change the port number in <VirtualHost> block from


<VirtualHost *:80>

to


<VirtualHost *:8081>

 

(Optional)

In case you want to change SSL port number from 443 to, say, 444, open SSL config file and change the port number as shown above for 000-default.conf. Also, change the <VirtualHost> directive in it use port 444


$ sudo nano /etc/apache2/sites-available/default-ssl.conf

 

3. Restart Apache Server

Restart Apache Server to apply changes


$ sudo systemctl restart apache2.service

 

That’s it! Apache will start listening on the new port numbers.

 

 

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!