Article submitted by Kari Pahula. We are running out of articles ! Please help DPOTD and submit good articles about software you like NOW !

PHP is well known for its coding style, mixing HTML with source code inside special <?php code > tags. There are tools and frameworks for that kind of web development using other programming languages like Perl and Python, but there is one fairly surprising choice of programming language that you could use instead, namely C.

KLone is a web application development framework that takes HTML with C embedded in as its input and turns it all into a single binary that is the server and the web app in one package.

Let’s step through an example of how to make a simple Hello World type of web app. First off, apt-get install klone-package . That’ll install KLone and a few tools you can use in a Debian environment. Change to a directory where you have a write permission.

$ make-klone-project create -p myhello $ cd myhello-0.1

There will be a number of files and directories in the project directory. The important ones are debian/ , where you have the files necessary for generating Debian packages containing your web app. We’ll return to that part later on. For now, let’s concentrate on the other directory of interest, userdata/ .

$ cd userdata $ mkdir etc $ cd etc

Create and edit a file called kloned.conf .

server_list my_http allow_root yes my_http { type http addr.type IPv4 addr.port 8880 dir_root /www }

Now we’re ready for action!

$ cd .. $ mkdir www $ cd www

Create and edit a file called index.kl1 . Any files that end with the .kl1 suffix will be treated as HTML/C files.

<%! #include <time.h> time_t now; %> <html> <head><title>A hello world app for debaday</title></head>> <body> <h1>Hello World</h1> <p><% now = time(0); io_printf(out, "Time is now %s

", ctime(&now)); %> </body> </html>

That’s really all there is to it. Now, return to the project root directory and to build a kloned server, just run:

$ kloned-build -o myapp userdata $ ./myapp -F

That -F switch is there so that the server won’t start as a daemon. Now you can access http://localhost:8880/ with the web browser of your choice to see a friendly greeting and to know the current time. But this isn’t the whole story, yet. Stop the web app you just created, run apt-get install dpkg-dev and then do the following:

$ dpkg-buildpackage -rfakeroot $ sudo dpkg -i ../myhello_0.1*deb

You have just installed a Debian package containing your web app. As long as the package is installed, you can rely on having your app start at boot time.

If you want to see more examples of how to use KLone, feel free to visit KoanLogic’s web pages.

KLone is available in Debian in Etch and later, and in Ubuntu since Edgy.