Introduction: Host Your Website on Raspberry Pi

Raspberry pi is a low cost development board by the raspberry foundation,for this tutorial i am using the distro provided by adafruit that can be found at http://learn.adafruit.com/adafruit-raspberry-pi-educational-linux-distro/occidentalis-v0-dot-2 all you need to do is download the image and use WIN32 disk to burn the image on to the SD card. This tutorial is very different from rest and focuses on hosting a site from raspberry pi and make it accessible ONLINE (from anywhere in the world).

Step 1: Connect Via SSH

Now connect your raspberry pi to home router using a Ethernet cable. the ada-fruit image comes with SSH enabled so you can connect via SSH immediately.

now you should try to open a SSH session via putty to raspberrypi.local or the speccific IP address( if you have ur HDMI connected it should be there on you screen, or go to ur router config page(usually 192.168.0.1) and check for raspberry pi under DHCP). you can log in to the raspberry pi with user name :pi and password :raspberry.

Step 2: Setting Up You Rasberry Pi

once you have a new installation there are a few things you should do to get things going, that includes expanding your root file system to fit the entire memory card and changing the user name and pasword. executing
sudo raspi-config
will take to to the config page where you can configure your PI.

Step 3: Installing Your Server

Now you have to install a server on the raspberry pi, the easiest is the Apache Server (Lighttpd also works if you are looking for something lighter) run the following commands to install Apache, PHP5, PHP5 mod for apache and MYSQL( if you are planning to use a CMS or a database.

sudo apt-get update

sudo apt-get install apache2 php5 libapache2-mod-php5


now you should allow overrides by editing the 000-default file, you can do that using the following comands..

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

now edit the following lines

change "AllowOverride None" -to "AllowOverride ALL".

now execute 

sudo service apache2 restart

to restart apache witht your new settings

now your site should be up and running u can go to /var/ and change the permissions on www, making it writable.

cd /var/
sudo chmod 777 /www


this will enable you to login using WINSCP and upload HTML pages to your new site. open the browser on your PC and point to 192.168.xx.xx (ip address of you raspberry pi) to view the default page.

You can also install and SQL server using the following comands, with a PHP and SQL running on your server u can have a CMs like Drupal running on it.

sudo apt-get install mysql-server mysql-client php5-mysql

Step 4: Setup Up PORT Triggers

Now you should have your server running, go to raspberrypi.local or the ip address from your browser on your PC and you should see the default apache page.
This means your server is up and running.
Now the problem is there is no way to access this website from the internet (like if your friend in Mexico wants to see the site :-(  ).
so go back to your router config page and set the port triger as shown in the picture below. this tells the router if there is someone trying to send an HTTP request via port 80 forward the traffic to the raspberry pi. This make the raspberry pi accessible from the internet.

Step 5: Have Your Domain Name

Now you have a website that can be accessed from online, but most of you (like me) dont have a static IP (its too expensive), which means every 1day or so , your ISP might change your ipaddress(gateway) so you cant always type in the ipaddress and expect to see your website, so solve this we use a no-ip service that gets installed on the raspberry pi. This service runs on the raspberry pi and tells the no-ip server what your IP address is. No-IP gives you a domain name that will point to your last updated IP, all you have to do in make a free account at set and regiter you hostname it will look like (rspi.no-ip.org) you could also go for a premium domain name. once that is done, type in the following commands to install the service....

cd /usr/local/src/

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

cd noip-2.1.9-1/


sudo make install

after the install is finished, it will automatically start the configuration, enter the username and password of the no-ip.org to finish the installation.

now you have your server set up successfully now all you have to do is make sure it runs every time you start the raspberry pi. there a couple of ways to do this, this i feel is the most easy one.

cd /etc/
sudo nano rc.local


add the following line , in the rc.local file to make noip service run during startup
sudo noip2

ctrl-x 
to close the file and save the file.

now reboot the PI by the following comand

sudo reboot

Step 6: Visit You Website

after setting up the no-ip service, you should be able to access the website hosted on your raspberry pi using the domain name you chose. You can test if the noip service is running by the following command.

sudo noip2 -S

if you see an valid PID, it means you have the service now running.... upload a few pages and hav fun!!

Comments

author
IqbalP6 (author)2017-02-09

can you give me an another free domain name like no-ip.com. my port 80 was block by isp .

author
PremU (author)IqbalP62017-08-24

During the install, you may decide to change port. By default it will be 80.

author
IqbalP6 (author)PremU2017-09-13

ok sir

author
jaleksandar (author)IqbalP62017-09-13

i use dataplicity, its free and easy to use... you can give try, but only to be able to use custom name for website you need to pay, as free you get rendom... but one line code to put in raspberry pi and its done...

author
IqbalP6 (author)jaleksandar2017-09-13

ok tq

author
schmidhamer (author)2017-04-01

can you run 2 websites from the one pi I have a business I am setting up and my wife has one also and if we could put both on my pi that would save us some money.

author
venkateshv30 (author)2017-03-10

suppose if i connected to mobile hot spot to raspberry pi how to set up port triggers

author
AkangB (author)2016-11-30

ok

author
JbT5 made it! (author)2016-11-22

Hey,

I got a problem when I am doing the installation by writing "sudo make install". I got this error :

"if [ ! -d /usr/local/bin ]; then mkdir -p /usr/local/bin;fi
if [ ! -d /usr/local/etc ]; then mkdir -p /usr/local/etc;fi
cp noip2 /usr/local/bin/noip2
/usr/local/bin/noip2 -C -c /tmp/no-ip2.conf

Auto configuration for Linux client of no-ip.com.

Connect to dynupdate.no-ip.com timed out
Network must be operational to create configfile. Ending!
mv /tmp/no-ip2.conf /usr/local/etc/no-ip2.conf
mv: cannot stat ‘/tmp/no-ip2.conf’: No such file or directory
Makefile:28: recipe for target 'install' failed
make: *** [install] Error 1"

Can someone tell what is the source of my problem ? Thanks

erreur.PNG
author
SP40 (author)2016-09-22

I have my personal domain, that purchased from goDaddy.... So how to use it to online/host site on Pi ?

author
Henkd11 (author)SP402016-10-17

From the goDaddy website:

"Simply sign in to your GoDaddy account and click on the Manage button next to Domains. Click Manage Connection or Add Website
under the domain you want to forward and select or enter the new
destination. Change it as often as you like – the whole process only
takes about two minutes."

author
MuBoks Stuff made it! (author)2016-09-17

Woo hoo i did it thanks allot man was really fun and a good project to do with my old raspberry pi 1 b

My site: http://muboksstuff.ddns.net/

66a88ba6def5bc53d9290eed6ad00fb9.png
author
BenV3 (author)2016-07-26

As of July 2016 the below line is not correct as the file 000-default does not exist. I find a file called 000-default.conf but inside this file there is no text that looks anything like the "AllowOverride" etc... can someone please tell me if this step is still required? If I do not edit this, does this prohibit me from setting up my website?

now you should allow overrides by editing the 000-default file, you can do that using the following comands..
sudo nano /etc/apache2/sites-enabled/000-default

now edit the following lines
change "AllowOverride None" -to "AllowOverride ALL"

author
josh-bacon (author)2016-02-09

Just out of curiousity, is burning the image onto the SD card easily reversible if you no longer want to run a server off your RPI?

author
DerP2 (author)josh-bacon2016-04-07

Yes of course! You only have to erase the memory (with something like PartitionWizard) and you can reuse the sd card

author
sajingeo (author)2015-01-05

when you are trying to access your website from the internet, check you internet IP address using google "what is my ip"(after you have setup port forwarding). you lan ip four computer is different from your WAN ip address of your router. To access your website make sure you enter the wan IP.

author
lcole1 (author)sajingeo2016-03-18

What you are saying is incorrect. If your WAN is something like 199.165.x.x, and your router is different, like 172.16.x.x, then chances are you are on your ISP's private subnet. There is no way to have a stable website this way. While your ISP may have their port 80 open on the 199.165.x.x IP, what you are actually doing is having a 'house party' on that IP, and hoping that no one else is hosting on that IP within the subnet. If another person does the same thing on your ISP's public IP number, both sites go down and chances are, your ISP blocks port 80 for everyone. It takes a tunnel to make this stable, and only the ISP could provide the tunnel you need. If your 'what is my IP' google search gives you a different IP than your router's external side, then you are on your ISP's private subnet. You are 'walled in', and cannot host (unless your ISP offers this 'extra feature', most-likely for a charge).

author
sajingeo (author)lcole12016-03-22

Yes, if someone uses the direct IP address to access the website and there is another user hosting at port 80 yes you will no longer see your website. That is why step 5 explains how to setup up no-ip so that you can map a domain name to dynamically changing IP address. the no-ip dns servers takes care of keeping track of you wan ip and routing the traffic to the correct ip address.

author
lcole1 (author)2016-03-18

Before the start of this explanation, the contributor should have mentioned that if you are on a subnet of your ISP, you cannot do this. To set up a Pi as a NAS Webserver on your router, you MUST have a public IP (you can check this by searching 'What is my IP' from Google, and if it does not match what your router tells you its IP is, then you are on a subnet (a private one) operated by your ISP, most likely with port-blocking in place to prevent two-way tunnels from being established). Check your IP, check against your router's external IP, and only if they are the same will this work. A hint that you are on a private subnet is if your router says it is at 172.16.x.x (a reserved private subnet sequence) or 192.168.x.x (another private reserved subnet sequence), you are basically 'walled in' and can't serve. Then, it's a provider or nothing (like GoDaddy).

author
luoX (author)2016-02-19

does this tutorial work for pi weezy OS?

author
PixelE (author)2016-02-12

This is the great article i really appreciate your post.

http://goo.gl/JdRxlC

author
PixelE (author)2016-02-12

This is the great article i really appreciate your post.

http://goo.gl/JdRxlC

author
jspobuk (author)2016-02-05

Thanks for the tutorial! Before I try this out, do you NEED to be able to port forward to host a website with Pi? I have an application where the only internet connection is using a cellular hotspot, and try as I might, I cannot port forward.

author
sajingeo (author)jspobuk2016-02-05

Most hotspot modems also have NAT or port forwarding. the problem is the Pi get a local IP address and the modem / hotspot get another public ip address. now the modem need to know when traffic comes on port 80 forward this to the Pi (local ip address). The modem will discard the packets if it does not now where to send the requests to (when you browser sends a request to the public ip address).

https://www.youtube.com/watch?v=O7CuFlM4V54

author
jspobuk (author)sajingeo2016-02-05

Thanks for the quick response and informative video. My issue is that when I use this device:

https://www.att.com/devices/netgear/unite.html#sku...

I can setup port forwarding on the device, but there appears to be another router on the ISP side that I cannot control. Any suggestions?

author
robbya4 (author)2015-12-11

Thank's for tutorial :)

author
SeAN15 (author)2015-05-31

So does this mean I can use my raspberry pi to have my web page online using my domain? I have a domain www.theridgeprogram.com/ so could I have my raspberry pi as the server instead of the paid web hosting, so everyone can see it?

author
DevB1 (author)SeAN152015-06-03

Yes, technically you should be able to do exactly that. Beware though that depending on the traffic your site receives, your pi and network connection may be overwhelmed. I found this fairy easy to do. Followed the steps given at

http://projpi.com/diy-home-projects-with-a-raspber...

author
SeAN15 (author)DevB12015-06-08

Thanks!

author
abel87 (author)2015-03-29

Nice!!!

author
JessicaH5 (author)2015-01-16

some packages, such as lighttpd and giving your Raspberry Pi a static IP address.

author
Pathfinder216 (author)2015-01-10

I'm having problems transferring html files. I got all the way through restarting apache (after changing AllowOverride None to AllowOverride ALL). When I tried the "sudo chmod 777 /www" command (after changing the directory to /var/), however, it gave me the response "chmod: cannot access '/www': No such file or directory." I installed WinSCP and found the www folder and I confirmed that the default site displays properly. When I try to transfer files it says "Permission denied."

Does anyone know what's wrong and/or how to fix it?

author

Okay, obviously I'm new at this. I solved my problem by dropping the forward slash in front of "www".

author
sajingeo (author)2015-01-05

you can also check if your website is up and running by going opening midori browser on raspberry pi and typing in "localhost"

author
sajingeo (author)2015-01-05

if you have the no-ip service on you router you can skip step

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

cd noip-2.1.9-1/


sudo make install

author
sajingeo (author)2015-01-05

Hi, yes you should he storing the index.html in /var/www/ . Some routers have no-ip service that you can enable from your router admin page. also make sure you have edited apache config file to allow all IP, but default the server might only allow you local lan to access the website

author
NicolasT (author)2014-11-26

Hi! Thanks for the tutorial, but I am still running into a few hurdles. I followed every step. Just to make sure, I am supposed to upload my index.html file to /var/www right? I do have a PID running, but if I try to go to my website, it only shows "400 bad request". Do you think you could help me?

author

Yeah I have exactly the same issue!

author

Hey, did you ever fix your problem? I am giving another go at this, and although I can access everything locally with no problem, I can't see to put it online.

author

I ended up doing a different thing. Where I set up no ip on my router and then set up port forwarding (also on my router) in conjuction with my RP. Let me know if you need help. I also tried using pagekite but that can get quite expensive depending on traffic. Even though I would definitely recommend it if I was creating a test server or something... But I am using my server as a backup site which obviously uses a lot of traffic... Hope that helps...

author

I know how to do port forwarding and stuff (I think!), but I don't understand when you say you set up noip on your router. Can you explain that part?

author
ron.fechtner (author)2014-12-15

Hey! Nice and easy to follow tutorial!
But even tho I double checked every step, I still cant reach my content.

Calling the Pi's Local IP through an other device's browser displays the
index.html in the /var/www folder properly, but using either the global
ip or the no-ip.org domain results in a network timeout error.

- noip2 process is running (pid, current global ip and noip-domain is shown)

- 000-defaults file is edited ("None" to "ALL" - also checked "All")

- No-IP Website show pi's currend global IP and No-IP Domain aligned

- Port-Forward for Ports 80 and 21 for the Pi's local IP are enabled

Any further advice?!
Thanks in advance
Best regards and keep up the intuitive tutorials

author

Running Raspian tho...

author

I am having the same problem I have gone through another tutorial too: http://forum.xda-developers.com/showthread.php?t=2019600 which uses PageKite rather than No-ip but pagekite is really expensive! Please let me know if you find a solution!

author

Do you think it may be to do with port forwarding?

author

Jup I contacted my IPS.. It's because im using global IPv6 adresses with Dual-Stack Lite. Therefore my devices do not get a global IPv4 adress to enable Port Forwarding... They offered me to activate the IPv4 (real Dual-Stack) for an additioal monthly fee...

Isn't there any way to achieve the same goal with IPv6 enabled on the Raspberry?! (Except Portmapping expensive services)

author
NicolasT (author)ron.fechtner2015-01-05

Hey! I was wondering if you solved your problem? I think I am in the same situation. I can access my website on my local network but not on the internet...

author
joaquin.pereira (author)2014-11-08

Excellent tutorial! Now i would like to get some security to prevent some hacking activity. Where i can find some info about this? I thinks is installing SSL or something like that. Do u know any info about this? Thanks!

author
Doug Paradis (author)2012-10-27

This is a very clear, complete, and easy to understand tutorial. Excellent work!

author
rahulr25 (author)Doug Paradis2014-08-12

Hey can u plz send me that tutorial? Am not able to get it.

e-mail : rahulr25@gmail.com

About This Instructable

275,301views

313favorites

License:

Bio: DIY, electronics...and loves getting creative...
More by sajingeo:Amazon Echo starts your carReal World MinecraftBluetooth Speakers using Raspberry Pi
Add instructable to: