Setting up the web server

The most classic web server on Linux is the powerful apache web server. Currently there is apache2, the second version of it. But on smaller devices apache2 might be considered as an overkill and a web server as lighttpd is recommended.

An other big issue is the performance of the CPU. Each time a key is pressed, the web browser must communicate this to the web server and the web server must react. On a full blown PC with a multi core CPU a straight forward approach using CGI (Common Gateway Interface) works without noticeable delay. However a small device as a raspberry PI will get delays of a couple of seconds when pressing a button. The problem is that when the web browser sends a key event to the web server (using CGI) the web server must load a python script in its memory including all libraries and then execute the code. Once done it frees the memory. This is simply too much stress to a small CPU.

The way out is FCGI (FastCGI). The implementation of FCGI is quite different. When the FCGI enabled web server is started also a python script is started. When the web browser sends a request to the server, the server can directly pass this request to the already running python script making use a the FCGI protocol. CGI script do not need any protocol since they simply echo or print their response to a pipe, whereas FCGI require an implementation of a TCP/IP based protocol. If more than one FCGI script would need to run, there would be still a single FCGI python script but this script would require to find out and dispatch the request to the selected script. A FCGI script dispatching those FCGI request is called a FCGI server. To not start from zero the python packet flup is used as FCGI server library. Unfortunately flup is old and its official maintenance stopped when python3 arrived. Luckily there are some ports to python3 around that girt makes use of.

Devices can access the web server directly using its IP address to not have a DNS setup.

There are many possible web server setups and every setup has again many options. This guide describes two out of them:

Apache2 with CGI

Usually the default setting will work well. Advanced setups as having multiple virtual hosts (vhost) are not discussed here. See

Make sure the web server contains a /var/www/localhost/cgi-bin directory and is able to execute scripts in this directory. As a simple test create a file /var/www/localhost/cgi-bin/date and give it executable permissions with the following content:

echo Content-type:text/plain

Type something as the following url in your browser and the date should be returned. If not CGI needs to be fixed on your webserver.


Commonly used locations for CGI scripts are:



The CGI script has to be placed to this location.

Lighttpd with FCGI

Setting up lighttpd with FCGI is more complex than the apache2 CGI setup. Details about lighttps setup can be found Important to know is that flup providing the FCGI server for python must be installed.

The FCGI script acting as FCGI server is called and its default location is /var/www/localhost/fcgi-bin (or /var/www/localhost/htdocs/fcgi-bin) The web server is setup-ed in a way that every request to /var/www/localhost/fcgi-bin will be passed to the FCGI server running in memory and the webserver will not look at the disk at all. The could also be on an other location than /var/www/localhost/fcgi-bin. It even could be on an other physical computer when lighttpd would communicate via TCP/IP.

Testing FCGI is not that easy. Some of lighttpd's config files might be Linux distribution dependent.

To have FCGI support on lighttpd its module needs to be enabled in /etc/lighttpd/lighttpd.conf

include "mod_fastcgi.conf"

and in /etc/lighttpd/mod_fastgci.conf to a fastcgi server must be configured as follows:

fastcgi.server += ("/fcgi-bin/" =>
         "socket" => "/tmp/fastcgi.socket",
         "bin-path" => "/var/www/localhost/fcgi-bin/",
         "check-local" => "disable",
         "max-procs" => 1,

And now the /var/www/localhost/fcgi-bin/ must be created with the following content.

#!/usr/bin/env python3

import sys, os
from flup.server.fcgi import WSGIServer

def app(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return ['Hello World!']  

Now lighttpd needs to be restarted. This also depends on the Linux distribution. On Gentoo making use of OpenRC it is /etc/init.d/lighttpd restart. Now http://localhost/fcgi-bin/ should pop up hello world.

When the FCGI setup for lighttpd works /etc/lighttpd/mod_fastgci.conf must be reconfigured to point to the FCGI server used by girt this will look as follows:

fastcgi.server += ("/fcgi-bin/" =>
         "socket" => "/tmp/fastcgi.socket",
         "bin-path" => "/var/www/localhost/fcgi-bin/",
         "check-local" => "disable",
         "max-procs" => 1,

Again lighttpd needs to be restarted to take notice about that change.

Obviously the javascript of girt must me configured that it uses FCGI and not CGI so call --fcgi

If the web pages are in some subdirectories of the web server than the relative path to the fci-bin directory must be set --fcgi --fsendkey ../../fcgi-bin/

Link to web pages

The default homepage is /var/www/localhost/htdocs/index.html. The program girt2html can copy everything under this directory or subdirectory.

It comes with a simple start page girt.html that can be directly called by a browser. On simple computers dedicated as IR sender a link can be made to have it as default web page:

ln -s /var/www/localhost/htdocs/girt.html /var/www/localhost/htdocs/index.html

This makes the web pages appear but the to have them functional more needs to be setup on the server. When a browser downloads a html page, the html page downloads also a javascript. When clicking on the page the browser executes the code of this javascript and the javascrips sends back over TCP/IP those events to the server making use of GCI or FCGI.

For the GCI script the location is /gci-bin

For the FCGI script the location is /fcgi-bin

girt2html -i will install the CGI or FCGI script. See girt2html -h for more details as adapting the destination.

Girt daemon

The CGI or FCGI script needs the permission to write to a named pipe (fifo) to exchange data with the daemon that does the work of sending out the infra red signals.

When started creates the named pipe that will appear as girtd.fifo file in the directory as ls -l shows prw-rw-rw- 1 lindegur users 0 Dec 22 14:56 girtd.fifo . The p indicates that is not a regular file but it is a named pipe.

The script or will write into this named pipe.

For testing and debugging purposes named pipes can also be dealt with within the console. The named pipe can be read similar to a file using cat girtd.fifo the only noticeable difference is that it blocks until something data has been received from the pipe or written to the pipe. Further useful commands are mkfifo girtd.fifo to create an empty named pipe and finally something as echo Hello > girtd.fifo to write to the fifo. It might happen that the web server setup causes troubles due to permissions. The console can be used in this case to locate the trouble.

The next thing is starting the daemon It handles the IR transceiver. After opening the virtual serial port on the USB as /dev/ttyUSB0 it continuously reads from that pipe and converts it into a message for the IR transceiver and sends it out. The program can be started in the console. The method to have it started on power up depend on the Linux distribution and system method (SysVinit, OpenRC, systemd, upstart). has a man page girtd.html

Linurs startpage