With Puppy version 4.1 our learned and wise leader Barry Kauler discovered a wonderful web-server Hiawatha Wikipedia Hiawatha-webserver - this web-server is small and fast in keeping with puppy philosophy.

The author of Hiawatha Hugo Leisink has written it with security at the front of mind. Barry's intentions were driven by the desire I believe to include the blogging software he uses PPLOG which is a small perl script. Consequently Hiawatha came configured by default to run perl as a CGI program to interpret .pl scripts (Hiawatha was left out of puppy 4.2.1) Investigation into Hiawatha shows it to be quite a performer in terms of throughput of pages served (purportedly twice as fast as Apache with static content) and appears to have much of the flexibility in its configuration as that available with Apache. Configuration options for virtual hosts, user and ip address based security and to run with ssl are easier to configure than Apache. It also has URL rewriting toolkit required to run many CMS applications. The problem with Apache is that is now quite large and it forks additional processes each requiring a large chunk of memory for additional connections. Performance in terms of memory utilisation is a snag particularly when many machines that run puppy may well be challenged in this department. We puppyofiles like to do more with less and Hiawatha with it's binary just 113k (as of version 6.16) running a multi-threaded rather than pre-fork model appears to be the perfect antidote to the Apache resource hog. (I have a 256Meg web-server on an old Athlon machine running our php/mysql/hiawatha squash court booking system, that has been running for months without a reboot and still has RAM to spare http://fraserparksquash.org.nz/Bookings/ - the apache squash file version had to have weekly reboots).

Pre-Fork or Multi-threaded web servers

Apache has the advantage that PHP can be run as a module - theoretically the fastest way to run PHP. However, the architecture of apache is based on a "pre-fork" model where new connections to an Apache web-server initiate new forks and each fork consumes RAM - so the machine can max out if a heavy load of web-serving comes it's way. Hiawatha uses a thread based model a similar architecture as that used by the fastest web-server (I understand this to be Roxen). This structure also has the advantage of being much leaner in terms of memory and ultimately faster to serve pages.

PHP as a Module or FastCGI

Running PHP as a module of Apache means that the PHP binary is already loaded when a request is fielded to run a PHP script and traditionally has been the favoured way of running PHP. However, development of Fast CGI also allows PHP daemons to be running ready to field requests thus reducing the overhead compared to running PHP as a CGI program - where it has to be loaded on each request - and holds a severe performance penalty. Hiawatha happily has the ability to run PHP as a FastCGI daemon. I have not done any bench-marking on performance of FastCGI Hiwatha PHP to Apache PHP moule - it would be interesting to see the results - it is my pick that Hiawatha/FastCGI PHP might well be faster.

Since Hiawatha is no longer included with puppy since 4.1.2 I made a new .pet including the whole bundle of software to turn puppy into a fully fledged web-server (hiawatha web-server, MySQL - RDBMS and the PHP interpreter that runs as Fast CGI daemons). It is available at:

This version released August 2009 is tested with Puppy 4.2.1 - and includes:

Hiawatha web-server version 6.16 (thanks to Prit for updating Hiawatha)

mysql version 5.1.35

PHP version 5.2.9

phpMyAdmin version 3.1.5

The .pet file is 11 Meg - so it is chunky by puppy standards - but includes mysql is a fully featured RDBMS and required by many applications. I have consoled myself that other LAMP implementations are many times the size.

This pet contains the necessary /etc/hiawatha/hiawatha.conf settings to serve .php web-pages with PHP running as a fastCGI daemons. Hiawatha comes with a program to launch a series of PHP daemons and again the config of php-fcgi is included in the .pet. The .pet also has a scripts in /etc/init.d/

rc.httpd that starts hiawatha on each boot

rc.mysqld that starts mysql on each boot

Both mysql and hiawatha httpd are started on each boot - if you do not want this to happen you should move one or both of these scripts out of the directory /etc/init.d

Both servers are started by the post installation script of the .pet so there is no need to reboot.

mysql is configured by a file in /etc/my.cnf and has been compiled to run as the user nobody - thus offering some protection from a rogue mysql problem damaging the system. Hiawatha also runs as nobody as do the php fastcgi daemons.

You can start mysql from rxvt:

#/etc/init.d/rc.mysqld start

and stop it with:

#/etc/init.d/rc.mysqld stop

Similarly you can start and stop hiawatha in the same way with the rc.httpd script.

Both php and mysql were compiled using devx_420.sfs as prepared by WhoDo for 4.2. Compliation options to exclude documentation (which is online) the mysql cluster code, the enormous mysql test-suite, the enormous PHP PEAR were used to minimise the size of the .pet but retain as much functionality as possible. PHP includes ftp, gettext, gd, xml, mysql and mysqli, sql-lite functionality. Mysql retains myisam, isam and innodb table types by default, together with all the usual mysql utilities including mysqldump, mysql client, mysqladmin etc.

The .pet also includes the phpMyAdmin php application for administering mysql databases - this is accessed simply from a browser pointing to:

The post installation script of the .pet runs the mysql_db_install script to set up the default database structure and mysql user database.

Normally with mysql installations out of the box, the default mysql user is root with no password. There are also 2 anonymous users that can access mysql without any permissions. However, the post install script now deletes both these anonymous users with the latest .pet and sets the root password for mysql as woofwoof

Important Note: Best practise is to alter the password for the mysql root user to prevent unathorised access to your databases see the mysql docs

The mail command of php allows sending of scripted email and is a useful function of php. However, it requires an sendmail compatible binary to be available or a local smtp server. The windows configuration just requires an smtp server but this option is not available in *nix.

After some research I discovered a neat work around using a small program called mini-sendmail - this is also bundled in the .pet
mini-sendmail allows you to specify a remote smtp server to use to forward your email from the php mail command. The configuration is straight forward and described inside the php.ini (see extract of php.ini below) that you should open with geany to modify for the smtp server you can access.

/etc/php.ini

<snip>
; mini_sendmail included with this distribution to prevent reliance on full send
mail
; mini_sendmail takes parameters:
; -f the from email address
; -s the smtp server to direct the email through - this allows a third party smt
p server to be used
; if the -s parameter is ommmitted then the localhost is assumed to be the smtp
server
; -t required for sendmail compatibility??
sendmail_path = /usr/local/bin/mini_sendmail -fyouremail@youremaildomain.com -
ssmtp.yourISP.com -t
</snip>

Where youremail@youremaildomain.com is the email address you wish to be reported as the sender of email coming from your web-server. and smtp.yourISP.com is an smtp server that your web-server can access.

The version before in December 2008 I added the libmcrypt.so library that created a problem in 4.1.1 and 4.1.2 - the fast cgi php daemons would not start because of this missing library and hiawatha would report service not available for php scripts.

Another issue that I experienced with gray's marvellous puppy-NOP pupplet was that the sticky bit was set on the /tmp directory - this prevented php running as the user nobody from creating session files in the /tmp directory. I had to run