Host Your Website on Raspberry Pi

299,041

326

69

About: DIY, electronics...and loves getting creative...

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!!

3 People Made This Project!

Recommendations

  • Plastics Contest

    Plastics Contest
  • Make it Glow Contest 2018

    Make it Glow Contest 2018
  • Optics Contest

    Optics Contest

69 Discussions

0
None
jhoogterp2016

Question 9 months ago on Step 3

When I sudo nano /etc/apache2/sites-enabled/000-default nothing shows up.
Please Help!

0
None
IqbalP6

1 year ago

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

4 replies
0
None
PremUIqbalP6

Reply 1 year ago

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

0
None
jaleksandarIqbalP6

Reply 1 year ago

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...

0
None
schmidhamer

1 year ago

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.

0
None
venkateshv30

1 year ago

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

0
None
AkangB

1 year ago

ok

0
None
SP40

2 years ago

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

1 reply
0
None
Henkd11SP40

Reply 2 years ago

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."

0
None
BenV3

2 years ago

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"

0
None
josh-bacon

2 years ago

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?

1 reply
0
None
DerP2josh-bacon

Reply 2 years ago

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

0
None
sajingeo

3 years ago on Introduction

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.

2 replies
0
None
lcole1sajingeo

Reply 2 years ago

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).

0
None
sajingeolcole1

Reply 2 years ago

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.

0
None
lcole1

2 years ago

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).

0
None
luoX

2 years ago

does this tutorial work for pi weezy OS?

0
None
PixelE

2 years ago

This is the great article i really appreciate your post.

http://goo.gl/JdRxlC