trying to update host settings

I am trying to setup Apache to run on port 8080 but I do not see the entries suggested how can I add them I have run sudo nano /etc/apache2/ports.conf

and this is what my file looks like

the tutorial says Find and change the following lines to have apache running on port 8080, accessible only from the localhost:

NameVirtualHost Listen

can I just add these lines to the ports.conf file ?

thanks Mike


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

The ports.conf file tells apache what ports to listen on for connections. The default is 80, but there are conditions for SSL if it’s enabled.

You can either add port 8080 or change from 80 to 8080.

Change the line

 Listen 80

To this line

 Listen 8080

If you use this syntax


Then it tells apache to listen to port 8080 on interface which is the localhost. That’s not what you want, because no one will be able to connect from outside. Just use Listen 8080.

Now, that will only tell Apache to listen on that port. You need to also tell it what websites are accessible from that port.

 $ cd /etc/apache2/sites-available
 $ ls

All the files listed here are the available websites. Each file should reference a <VirtualHost> that is configured for Apache.

You can control what port a virtual host will operate on, or you can use an * to indicate all ports.

<VirtualHost *>
 DocumentRoot /var/whathappentoday/web/www

 <Directory /var/whathappentoday/web/www>
    Options FollowSymLinks
    AllowOverride all
    Require all granted

 ErrorLog ${APACHE_LOG_DIR}/error.whathappentoday.log
 CustomLog ${APACHE_LOG_DIR}/access.whathappentoday.log combined

Other possible syntax is



 <VirtualHost *:8080>

Now, the NameVirtualHost directive is a little ambiguous. This tells apache what ports support virtual hosts that have a ServerName. I’ve never had to declare this directive to get named virtual hosts to work. If you want to declare the directive it would be like this, and put it in your apache2.conf file (not the ports.conf file).

NameVirtualHost *:8080

After you’ve made any changes to apache’s *.conf files you have to restart the server.

$ service apache2 restart

Thanks for clearing that up, maybe some of the tutorials should be updated to help us newbies out

thanks again