Create a Basic Website on a Raspberry Pi

The Raspberry Pi is a small Linux computer designed to help children learn programming. Being a full Linux System, it can also be used as a server or as the basis for various projects.

The Pi’s low power consumption makes it particularly suited to the role of always-on web server. This post describes how to install the Apache web server software and get a basic site going.

Install Apache

Install the Apache web server with these commands.  It might take 10 minutes or so to complete.   A few other packages will also be installed.

pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get install apache2

Behold! Your New Website

In a web browser, surf to the URL http://<ip address of your Pi>, and look at your new web site.

Note: The IP address of your Pi can be found with the ifconfig command:

pi@raspberrypi ~ $ ifconfig | grep inet
          inet addr:  Bcast:  Mask:
          inet addr:  Mask:

My Raspberry Pi’s IP address is, so I go to

You should see a web page with these words:
It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet.

The web page will be visible from any computer, smartphone or tablet on your home network, even in a browser running on the Pi itself.

Edit the Website to Add your Own Stuff

What you see in the web page is determined by an “html” file located at /var/www/index.html.  You can edit the file to add words, pictures, or whatever you like to the site.  Eg.

pi@raspberrypi ~ $ vi /var/www/index.html

Add a few words of your own and save the file. Surf to your web page again (or just refresh the page in your browser) to see the effect of the changes you made.

Many sites in the internet offer instructions on basic HTML writing. You can learn how to add text, pictures, links to other sites, and more pages to your own site.

Going Public

If you want to see the website from outside your own home, for example from your office or school, proceed as follows.

1. Make an adjustment on your home router to forward port 80 to the IP address of your Pi.  This is easy.  Just log into your router and follow the menu system to make the change. Port 80 is also called the “http” port.

2. Identify the public IP address of your home router.  You can get it from the router’s menu system, or just go to a site like, and it will tell you immediately.

3. At your remote location (eg school/office), just surf to http://<your public address>.  You should see your familiar web page pop right up.  It works from a smartphone too.

Dynamic IP Addresses

Note that from time to time your router’s IP public address will change.  To visit your website from outside, you will then have to get the new address again (eg. from and start using that.

Alternatively, get your own domain name.  You can then visit your site from outside by surfing to http://<your fancy domain name>, with no worries about changing IP addresses.  Many providers will give you a domain name for a small charge, and some provide them for free, eg

That’s it. Happy web authoring!

A Note on Security

If you followed the instructions above and made your Pi website visible from the internet (forwarding port 80 etc), that’s great. You now have your own internet server. Like all “internet facing” servers, your Pi should be kept up to date with the latest security patches. Do that by running these commands every couple of weeks:

pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get upgrade dist

(Note: that last command, if you have never run it before the Pi, will download many updates and take an hour or two to complete. Subsequent runs will complete in a couple of minutes though). Finally, reboot the Pi so the updates can take effect:

pi@raspberrypi ~ $ shutdown -r 0

Thanks for reading. And don’t forget, next time your family/friends are going blah about Twitter/Facebook, just tell them you have your own internet server.

2 thoughts on “Create a Basic Website on a Raspberry Pi

  1. Pingback: Raspberry Pi Basic Configuration | Unix etc.

  2. Pingback: Simple Picture Gallery on Raspberry Pi | Unix etc.

Leave a Reply

Your email address will not be published. Required fields are marked *