apache2: change apache port

Generally, the port for apache is 80, when we type http://localhost, it listen to port 80 which is default for apache server. During some other purposes like, managing system in a LAN [wikipedia], which shares same name, or for securing the apache port, to avoid anonymous view.

First took our famous tool known as Terminal Applications->Accessories->Terminal

Step1: Make a backup copy of ports.conf

sudo cp /etc/apache2/ports.conf /etc/apache2/ports.bk.conf

Step 1: Open the following location in a text editor. I am using it with nano.

sudo nano /etc/apache2/ports.conf

Step 2: Change the following, I am changing the port 80 to 8010.

NameVirtualHost *:80
Listen 80


NameVirtualHost *:80 10
Listen 8010

After that, you need to make sure that you are using the now declared VirtualHost in a config file. Check in /etc/apache2/sites-available/ for a site using your Listen port:

grep -E '<VirtualHost [*0-9.]+:8010' /etc/apache2/sites-available/*

If any lines are returned, then you have something setup to use that VirtualHost. If not, then you need to create another site in your config. The easiest way to do this is to copy the existing one and edit it slightly. In Step3 we are copying.

Step 3: Copy /etc/apache2/sites-available/default to /etc/apache2/sites-available/default8010

sudo cp /etc/apache2/sites-available/default to /etc/apache2/sites-available/default8010

Step 4: Open default8010 with a text editor, and change the following.

Change the line that says this:

<VirtualHost *:80 >
to this

<VirtualHost *:80 10 >

Save the file and exit. Now you should enable the site

Step 5: Enable the site using a2ensite

sudo a2ensite default8010
sudo /etc/init.d/apache2 reload

Now you should have a site enabled, listening on all interfaces on TCP port 8010.

I would like to thank giggins[link], of ubuntu forums [link], for helping me to solve this problem.


Post a Comment