/RaspberryPiServer
The Raspberry Pi (often referred to as “RPi” or “Raspi”) is a great option if you are looking for a low-cost, personal webserver that can be used as a low-volume webpage host, a testing server, or for your business or home’s intranet. It has a very small footprint, both physically and environmentally (its power draw is around 5 watts), the equipment costs about as much as a few months of commercial website hosting services, and having your own system gives you far more flexability than using most commercial services.
- Raspberry Pi [I’m using a Model B Raspi]
- SD memory card [I have an 8GB Class 10 SD card for fast data transfer]
- Power adapter compatible with the MicroB [I use an old cell-phone charger that delivers 1A current –- I do not recommend using one rated at below 750 mA since it may cause the Pi to freeze]
- Ethernet patch cable OR WiFi dongle
- Monitor & Cable [only needed for initial set up]
- USB Keyboard [only needed for initial set up]
I am using Raspbian “Wheezy” for this project, however, there
are many OS distributions offered for the Raspberry Pi that will
work just as well. Use whatever stable distro you prefer.
If you do not already have an OS loaded onto your SD card, you
will have to download a disk-image copy and write it to your
card using a program like Win32 Disk (for Windows) or
usb-imagewriter (in Ubuntu Linux).
Once the image is written to the card, plug everything
(keyboard, SD card, Ethernet/WiFi dongle, &c) into the RPi and
power on the device.
The first thing you have to do when you load your RPi for the first time is set up the system using raspi-config. You should take your time here and make sure to set the system clock, enable SSH (optional), change your password(!), open the entire SD partition for use by root, and disable boot to desktop. You can also update your RPi through this interface and reboot using:
sudo reboot
*You can also update from the terminal using:
sudo wget https://github.com/Hexxeh/rpi-update -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update sudo rpi-update sudo reboot
I recommend using an Ethernet patch cable to connect directly to your internet router at home. In this set up, most routers will automatically set you up with a network IP and get the RPi internet access.
However, if you want to set this system up on a home WiFi, it's not too difficult. You will have to use a WiFi dongle and configure the RPi to automatically connect to your network:
#Install wicd-curses for a nice interface to scan WiFi networks. sudo apt-get update sudo apt-get install wicd-curses #Set wifi settings sudo nano /etc/network/interfaces auto lo iface lo inet loopback # Temporarily disable ethernet #auto eth0 #iface eth0 inet dhcp auto wlan0 iface wlan0 inet dhcp wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp #Set up your WiFi access points. sudo nano /etc/wpa_supplicant/wpa_supplicant.conf ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="YOUR HOME WIRELESS NETWORK" proto=RSN key_mgmt=WPA-PSK pairwise=CCMP TKIP psk="YOUR PASSWORD" }
Optional: at any time from here on, you can connect to the RPi remotely using SSH (assuming you enabled that option in raspi-config). To do this, you will have to determine the RPi’s local IP address typing ifconfig from the command line. The Pi’s IP should look something like 192.168.x.x. You can then run your Pi from another computer by using a program called PuTTy in Windows or simply by typing in ssh pi@192.168.x.x (where 192.168.x.x is your Pi's local IP address) into the command line on Macs or linux machines.
Most people will use FTP to upload files to the website.
#Set up FTP sudo apt-get install vsftpd sudo nano /etc/vsftpd.conf # Change the following lines: anonymous_enable=NO local_enable=YES write_enable=YES # Add to Bottom of File: force_dot_files=YES sudo service vsftpd restart #Allows you to write to /var/www using ftp client. sudo usermod -a -G www-data pi
I am using Nginx for my server, which is a lot like Apache, but more lightweight:
sudo apt-get install nginx #Packages depend on the type of Website you've got. sudo apt-get install php5 php5-fpm php5-cgi php5-cli php5-common sudo useradd www-data sudo groupadd www-data sudo usermod -g www-data www-data sudo mkdir /var/www sudo mkdir /var/www/seanmobberley/ sudo chmod -R 775 /var/www sudo chown www-data:www-data /var/www sudo chown www-data:www-data /var/www/seanmobberley/
At this point, you can FTP upload your website files to your newly made website root directory on the RPi at /var/www/seanmobberley/, for example. To upload, I use FireFTP and connect with the RPi on its local address, e.g. 192.168.0.21 from my main computer.
Setting up a virtual host with Nginx. Next, we make a directory for activating the website in Nginx:
sudo nano /etc/nginx/sites-available/seanmobberley #Basic Config server { listen 80; server_name seanmobberley.com; # $scheme will get the http protocol # and 301 is best practice for tablet, phone, desktop and seo return 301 $scheme://www.domain.com$request_uri; } #This first server block just takes "seanmobberley.com" and renames/redirects to #"www.seanmobberley.com" - you can also do it the other way around if you want. server { server_name www.seanmobberley.com; access_log /var/log/nginx/seanmobberley.access.log; error_log /var/log/nginx/seanmobberley.error.log; #Error Redirect error_page 404 /404.php; ### Default location root /var/www/seanmobberley; index index.php index.html index.htm; ### GZIP gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 32 16k; gzip_http_version 1.0; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml text/javascript application/javascript text/x-js; ### Static content passed through location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ { expires 5d; access_log off; } #if the URL with .php tacked on is a valid PHP file, rewrite the URL to .php if (-f $document_root$uri.php) { rewrite ^(.*)$ /$uri.php; } # use fastcgi for all php files location ~ \.php { try_files $uri =404; include /etc/nginx/fastcgi_params; keepalive_timeout 0; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; } # deny access to apache .htaccess files location ~ /\.ht { deny all; } }
Finally, we symbolically link the file to enable the website.
sudo ln -s /etc/nginx/sites-available/seanmobberley /etc/nginx/sites-enabled/seanmobberley sudo service nginx restart
Now, you should be able to see your site by opening up a browser and going to http://192.168.x.x - i.e. your host IP address. If you do not know your IP address you can easily find out what it is by opening a command line and running ipconfig (in Windows) or ifconfig (in Linux/Mac).
If you get a 403 - access denied error, try redoing the folder permessions using:
sudo chmod -R 775 /var/www
After you have set up Nginx/Apache on your host server, you will want to be able to access your server from devices beyond your local network.
If you connect directly to your ISP and are on a static IP that doesn't begin with 192.x.x.x or
172.x.x.x or 10.x.x.x, than you have nothing to see here, carry on.
Otherwise, if you are like the 99% of people who are behind some kind of router/proxy/firewall, you'll
need to open up port 80 on the firewall and forward it to your computer.
To do this, you will have to get on to your home router's configuration page. For most routers,
you can get there by entering the router's gateway IP into a web browser and entering the router's
admin user and password info. If you are not sure how to do this, check out your router manual.
Once you are on the router's configuration page, look for a port forwarding option.
Since outside computers and networks can only see your router's public IP
(i.e. 66.177.188.199, or something that is NOT 192.168.x.x) you will have to use Ports to direct
external requests. It works just like a call center at a large company: people will call the
business using the main line (e.g. 800-555-4444 or 151.123.200.50) and enter an extension (e.g. ext555
or :80) which directs the request to the appropriate phone or computer.
You can make this happen simply by entering your Pi's local IP (e.g. 192.168.0.21) on the Port Forwarding page and using the port
80 (or 8080 or anything else you want that doesn't conflict with other programs). Once you do this, you
should be able to connect directly to the Pi through computers/devices that are external to your home
network by using your router's IP and the RPi's forwarding port, for example 66.177.188.199:80.
If you want a named address, like seanmobberley.com instead of a IP number, you will have to register your name on one of the many name hosting site on the internet.
I recommend you do a little bit of research on this and go with a company you trust and provides the features you want (like dynamic DNS).
You shouldn't have to pay much more than $10/year for a .com from a good company.
Whatever site you choose, use their DNS service and edit the host record to use A (Address) and enter your router's external IP to get your site fully on the internet!
If, like most people with cable/DSL, your public IP changes often, you will want to set up some kind of Dynamic DNS client to automatically let your web-name provider know when it changes. Since I use namecheap.com (who provide free Dynamic DNS service), all I had to do was install DDClient on my RPi and edit the config file:
sudo apt-get install ddclient #If you are also using namecheap.com, it does not matter a whole lot what you #answer in the DDClient configuration/set up. #You will still have to edit the DDClient's configuration file: sudo nano /etc/ddclient.conf ############### # ddclient.conf # namecheap ############### daemon=3600 #check for an IP change every hour (ddclient will only send updates to namecheap IF there is an ip change) use=web, web=checkip.dyndns.com/, web-skip='IP Address' #use the web to check your public ip protocol=namecheap server=dynamicdns.park-your-domain.com #this is the name of namecheap's server login=seanmobberley.com #yoursite.com password=faefjawpefoij30498320493r23 #this isn't my real password @, www #yoursite.com and www.yoursite.com
*Your password will be provided by whoever you are getting your Dynamic DNS from.
If you have any Access/403 errors, recheck your file/folder privileges. You can view them by the command ls -l /var/www/seanmobberley/index.html, for example.
You can change permissions using the command sudo chmod 775 /var/www/seanmobberley/index.html, for a single file. Or use sudo chmod -R 775 /var/www/seanmobberley/, to change permissions to all the files in a directory and all subdirectories.
Tip: check your error.log file when you start the web page and any time you update major content.
Tip #2: make sure your site works well in all the major browsers: IE / FF / Chrome / Safari / Android / etc.
There are websites out there that can help you out with that.
/R&DProjects
Radioactive Waste Gas Containment System
Pneumatic Silicone Arm With EMG Activation
Homemade Schlieren Optical System