Changing The TCP Port On The Apache Web Server

If you wish to give the rest of the world access to your Pi and you haven't any spare external IP addresses available, you will probably want to change the port number that the Pi's Apache webserver uses to listen and respond so that you can forward that port on your firewall or router. Assuming that you have set up your firewall correctly, by allowing traffic in and out to your Pi on, say, port 8080, then you need to change your Pi as follows.

At the Pi command line, edit the Apache ports configuration file ports.conf:

sudo nano /etc/apache2/ports.conf

Now change the entry for NameVirtualHost to *:8080 and the entry for Listen to 8080. Save the changes and exit.

Now edit the file 000-default and change the entry for VirtualHost to *:8080. Save the changes and exit.

sudo nano /etc/apache2/sites-enabled/000-default

To make these changes live, you need to restart Apache so that it reloads the new configuration.

sudo /etc/init.d/apache2 reload

You should now have your Pi accessible from the Internet by connecting to it as http://<your-external-IP-address>:<8080>.