Intro: Setting Up Raspberry PI As Webserver
Finally I have decided that sharing my collected notes and put it into
some readable format. Yes, the Raspberry PI craziness that nowdays sweep through the internet touched me as well. I could not just pass it and not get one. I have ordered the RPI Model-B rev-2 version with 512Mbyte of RAM, 4Gb SD card and passive coolers. Actually I wanted to use it as own webserver and creating a blog which running on the machine. Because I thought it would be cool sometimes use it to playing films just wanted to connect it to my Samsung TV through HDMI. Of course not to use it uncomfortable directly keyboard and mouses but get the X layout of RPI from remote desktop.
Motivation and decision
- Small board, impressive, attractive and cheap computer
- Hackable Linux based platform provided with ATM chipset
- Low electricity consumption
- Silent machine with possible passive cooler
- Own webserver. It’s not on the other side of world holding a 3th party ownership
- Mini file server for notes and not too large files
- Reusable for several projects
- Hardware and software in one hand
Step 1: Get Simple Box for RPI
I prefer the simple but clever solution. I was seeking something easily accessible box for RPI and surfed the web when I found a creative but easy solution: LEGO. On the net there are lot of cool skins for RPI but just spent some hours to looking for my old LEGO pieces and started to build it. The RPI board fits in a LEGO enclosured box with dimension of 9 x 13 blocks. Perfect. Because Raspberry PI is small still with the box, the best place was it to me put it behind the TV. It can be easily connected to TV through HDMI. Because the on the board there is not any cooling solution I have also bought a passive coolers which ones just had to stick on the chips. In the most RPI stores can be ordered a prepared package contains three passive coolers for every important chip on RPI board.
Step 2: Doing the Software Way..
There is a set of compatible operating system to RPI for different purposes. At first testing I have just installed the most popular Debian Wheezy system with X layout. Because it may exists better OS for my purposes (e.g. running only webserver I would use the faster Risc OS) but I didn't want to reinstall a new one so it remained. Download OS here and how-to burning the image on SD card can be found here: www.raspberrypi.org/downloads
Let's do the necessary settings, install the softwares and libraries.
- passwd # change password from 'pi'/'raspberry' to new one
- date +%T -s "20:58:00" # set time
- dpkg --get-selections # checking what we may need to have
- sudo apt-get update # get recommanded software updates
- sudo apt-get install xrdp # server for remote desktop protocol
- sudo apt-get remove nano # remove unnecessary sofwares ...
- sudo apt-get install vfstpd # secure and fast FTP server
- sudo vi /etc/bash.bashrc # write psg="ps -aux | grep" to use psg alias
- !FTP 550 permission upload # problem solving
- !sudo vi /etc/vtftpsd.conf
- !sudo service vsftpd restart
Use this one to know what happens on RPI because the programs are installed here
logging in this file.
- tail -f /var/log/messages # always checking knowing problems
Installing Virtual Network Computing program (VNC) to handle RPI from remote.
- sudo apt-get install tightvncserver # get the VNC server to get new X displays
- !vncserver :1 -geometry 1280x800 -depth 16 -pixelformat rgb565: # start
- !sudo chown pi /home/pi/.Xauthority # problem solving
- !vncpasswd view-pass NONONO # recover password
- sudo apt-get install x11vnc # get the real X displays
- !startx& # start X desktop
- !vncserver # start VNC
- !x11vnc # start X11VNC
- !# From now you can connect with vncviewer on 0 display to get real RPI display
Testing pendrive. I had no problem the automount worked well on X display and the a folder came up.
- /kernel/sda/sda1 # the path of automounted pendrive
On the net there is a lot of available webserver on different size and for different purposes. Because of RPI is not made of running heavy webservers I wanted to spare with the load and space (my SD card is only 4GB). And earlier I have decided that I want to create so kind of blog that does not need database and as it possible it avoids the dynamically elements. Decision to lightweight webservers. Comparsion of lightweight webservers. Here you can find a cool analysation of lightweight webservers:
May it recommended from RPI community? Nginx (6,2000Kb on my SD card).
- sudo apt-get install nginx # get nginx webserver
- sudo useradd www-data # user grant to user of webserver(s)
- sudo groupadd www-data # group grant to user of webserver(s)
- sudo usermod -g www-data www-data # changing user group of user
- !/usr/share/nginx/www/ # path to put the pages
Mplayer, settings sound
Playing films and music or just listening to radio, do the compulsory settings.
- sudo apt-get update
sudo apt-get upgrade
- sudo apt-get install mplayer mplayer-gui alsa-base alsa-utils pulseaudio mpg123
- sudo usermod -aG video pi
- sudo amixer cset numid=3 # http://elinux.org/R-Pi_Troubleshooting
- mplayer -fs xy.avi # fullscreen mplayer from consol
- mplayer -ao alsa -playlist "http://184.108.40.206:8003/mp3.m3u" # FM online radio
Step 3: Blogging Motor
On this section I don’t want to waste the time to reason why it’s good keeping the things as simple as possible but one of the possible way to do it with static blog generator. My requirement was a quite high performance blog platform, track content changes easily, writing posts (using Markdown), publish them in easy format but still holding posts in logic structure like a blog. I wanted to eliminate the complex and large webservers (as I did it with nginx) so being on this way wanted to do it with blogging method as well. There is no need dynamic websites, frameworks systems (CMS), database request and other overheads, instead of them just using static HTML pages.
The other reason is when once I would like to move on or whatever editing the contain I just simple handle it. No database requests from several tables, no different technology chaos to put the contain in readable format, no dynamic pages, no annoying porting necessaries. Small size, python script, more than enough to my purposes. A simpatic static generator: Mynt. Mynt supports custom date, tag-based archives, Markdown posts, Jinja templates and YAML front matter.
First I had some problem with different mynt versions and got python compile errors. Because I could not find the solution on forums, in IRC channel Anomareh the developer of mynt helped me to fix it. I was using mynt 0.2.2 instead of 0.2.3 with jinja 2.7.
- sudo apt-get install nedit # get text editor with highlightings
- sudo apt-get install git sudo apt-get
- install python-dev sudo apt-get
- install python-pip sudo pip
- install mynt # get static site generator
Static address for global access
Okey! We got webserver, blogging platform and so static HTML pages. Open
the door and make it available from internet. If you want to use free DNS, register at on of the free dynamic DNS service and get a simpatic domain name. I’ve used this one: http://freedns.afraid.org/.
Install ddclient client used to update dynamic DNS entries for accounts on Dynamic DNS Network Services' free DNS service. When it is done and the settings are correct, go to settings menu of your router (e.g: 192.168.1.1) and create an open port (do port forwarding) that allow a connection in to your home network from the Internet. To get to know your external IP and port using RPI, here is a site (port 80 for webserver).
More details about the port forwarding at specific router check this site.
- sudo apt-get install ddclient # get ddclient
- sudo vi /etc/ddclient.conf # protocol=dyndns1, server=freedns.afraid.org, login and password
- sudo vi /etc/default/ddclient # run_deamon="true", run_ipup="true"
Commands make sense
Some commands I was using during the installation process, they may be helpful.
- mynt --version # current version of mynt
- mynt init ~/src # initializing new site
- mynt watch -f src/ res/ # automatic regeneration after site modification
- du -ch # current files total in readble format (Kb, Mb, etc.)
- df -h # filesystem disk space usage in readable format
- shutdown -r now # restart rpi
- shutdown -h now # halt rpi
- /opt/vc/bin/vcgencmd measure_temp # GPU temperatur
- /sys/class/thermal/thermal_zone0/temp # CPU temperatur (is the first two digit)
- sudo apt-get install vnstat # network traffic,
- vnstat --dumpdb
- sudo cat /var/log/nginx/access.log # nginx log about visitors
- netstat -t -u # TCP and UDP connections
Step 4: Experience
My RPI had been ran for 15 months without problems. Sometime I’ve checked and cleaned the dust around the box that was until now the maintenance. The webserver is also working well but of course it is not sized to heavy-load. I think to get the passive coolers was also a good idea. Sometime I’ve checked the temperature of chips (or just touched them with finger) and after a film watching, of course an active using it was really hot with the passive coolers as well. What’s else would be without them?!
To powering RPI I use a typical Samsung charger and had never problem with that. (On forums it can be read about some cheap and after made charger which is not working appropriate e.g.: problems reading pendrive or not powering the RPI.)