At the moment when you enter http://servername into your browser, you should see your default Apache web page. This page is only accessible from within your local network.
We now want to access the web site from outside the home network in the same way as any other web site.
You will need access to your router and the procedure will vary depending on the router so you may have to find the documentation for it.
Log in to your router and find a screen in the menu system that allows you to set port forwarding. You then have to add in the Raspberry Pi IP address so that HTTP requests on port 80 are forwarded to your Raspberry Pi from the internet. You will also want to make sure that outbound requests to the internet on port 80 are also allowed for that IP address.
Hosting on a dynamic IP address
Now you have a web site which can be access through the internet but you probably have a dynamic IP address for your connection from your router to your internet service provider. This means that it will change if you reboot your router or if your service provider does a change. You could obtain a static IP address but that may be too expensive so one way to overcome this issue is to use a no-ip service.
You install a script on your Raspberry Pi which is run at regular intervals, usually every 30 minutes, and informs the no-ip service what your IP address is. You can have a domain name on the no-ip service which is then connected to that IP address.
You can do this on no-ip.org which is a free service.
Log into http://no-ip.org and create a user account. You can create a free domain name as well, providing that it meets the requirements of no-ip.org. You can go for a premium account if you wish.
To install the require script on your Raspberry Pi enter:
sudo wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
tar xf noip-duc-linux.tar.gz
sudo rm noip-duc-linux.tar.gz
sudo make install
You may have to change the permissions of the folder to allow the make to work.
After the install is finished, it will automatically start the configuration, enter your username and password of the no-ip.org to finish the installation.
You should now be able to access your web site using your domain name.
Now you have your server set up all you now have to make sure it runs every time you start the Raspberry Pi which can be done as follows:
sudo nano rc.local
add the following line in the rc.local file to make the noip service run during startup
Press ctrl-x to close the file and save the file.
Now reboot your Raspberry PI using:
You should be able to access your web site using the domain name.
You can test if the noip service is running by typing the following command:
If you see a valid PID it means the service is running.
(1) The username (email address) that you set up for your account on the no-ip web site is tied to the update process so if you change your email address in the no-ip web site, you have to change the configuration of noip service.
(2) To view commands that are available do noip2 -h in the terminal.
(3) To change the configuration do noip2 -c in the terminal.
(4) To check the configuration details do noip2 -S in the terminal.