Using Lighttpd rather than Apache

Using Lighttpd rather than Apache
DAViCal works mostly fine using Lighttpd however DAViCal is not a web application, in the sense of something like Drupal, Joomla, Flickr or Facebook. Rather, it is an HTTP application, needing full access to various header information passed to the webserver by the CalDAV client software.

Many web application stacks tend to assume that applications will only use GET and POST methods, for example, whereas DAViCal needs to receive the full request data for many other http methods including PUT, MOVE, PROPFIND, PROPPATCH, REPORT, MKCOL, MKCALENDAR and more.

As a result you may have increasing difficulty getting more obscure parts of DAViCal's functionality to work with FastCGI, such as creating calendars from within CalDAV client software.

Advantages
Lighttpd occupies a different, low-resources spot in the memory/CPU <-> facilities trade off. Owners of low memory/CPU systems, routers, ARM-powered devices (e.g. nslu2) may prefer using lighttpd rather than Apache as their web server.

DAViCal + PostgreSQL + lighttpd for personal use can squeeze into a 16 MB system and is very comfortable on a 32 MB system with no swap and 2 GB storage. Apple's Darwin Calendar Server does not fit into such systems.

Summary
DAViCal in Debian is now web server agnostic.

(1) Install, setup and test Lighttpd with (fast)cgi PHP support -- this will not be covered here, there are plenty of other web resources for this relativity easy task;

(2) Install DAViCal with apt-get install davical. Make a symbolic link in your webspace to \usr\share\davical\htdocs

(3) Setup DAViCal, we follow the notes on this website Installation_Guide_Update, Installation_Guide_Update_%28Feb_2008%29 and Installation_Experiences.

Install
(1) Lighttpd in Debian will by default create the webspace at /var/www.

(2) Below is a single line apt-get for Debian that will install all dependencies save Apache. Now DAViCal does not include Apache in its dependencies this is a simple line!

sudo apt-get install lighttpd davical

For Debian Squeeze you need the following line to avoid apache2 being installed:

sudo apt-get install lighttpd davical php5-cgi

-- Now DAViCal is installed with Lighttpd and ready for setup.

Make sure you activated the required lighttpd modules:

lighty-enable-mod fastcgi-php fastcgi service lighttpd force-reload

Setting up the Database
In order to use DAViCal the postgres database needs to be created. The following brief dump of commands follows Installation_Guide_Update, Installation_Guide_Update_%28Feb_2008%29 and Installation_Experiences.

sudo su postgres -c "createuser davical_app" sudo su postgres -c "createuser davical_dba"

Now add these lines to the TOP of /etc/postgresql/8.X/main/pg_hba.conf" (and certainly before any other 'local' ones (otherwise you may get a 'FATAL:  Ident authentication failed for user "davical_app"' error report).

local all all trust local davical davical_dba trust local davical davical_app trust

Now create the DAViCal database:

sudo su postgres -c /usr/share/davical/dba/create-database.sh

You will see an output like : Supported locales updated. CalDAV functions updated. RRULE functions updated. Database permissions updated. NOTE ==== * The password for the 'admin' user has been set to 'NOTE_PASSWORD_HERE'" Thanks for trying DAViCal!  Check in /usr/share/doc/davical/examples/ for some configuration examples.  For help, visit #davical on irc.oftc.net.

Note the password, you will use it to login as admin to set up user accounts in the web interface. Once the creation script has run correctly, go back to the pg_hba.conf file and remove the line:

local all all trust

Configuring Davical
Now we create the davical confid files:

cd /etc/davical/

Create the very simplest localhost-conf.php etc files -- check documentation for many more options:

admin_email = 'admin@example.net'; // $c->system_name = "DAViCal CalDAV Server"; $c->pg_connect[] = 'dbname=davical user=davical_app';

For those who know, we intentionally left off the closing ?>.

Now make symbolic links (or, hey, just copy the file) for each hostname you use e.g. myhost.dynadns.org-conf.php, www.bought-ip-address.com-conf.php or just 192.168.0.1-conf.php.

Note DAViCal uses the SERVER_NAME as supplied in the http request and forwarded to DAViCal by the cgi interface to pick a *-conf.php file. This means that if no server name is specified in the http:// request -- i.e. if accessing with an IP address like http://192.168.0.1/... -- then the config file name will be -conf.php, quite awkward.

To avoid this make sure a default server name is specified in the /etc/lighttpd/lighttpd.conf, even if it is the IP address:

simple-vhost.server-root = "/var/www" simple-vhost.default-host = "192.168.0.1" simple-vhost.document-root = ""

You should be good to go now.

Access DAViCal at http://address/cal set up an user account which you can the use with you CalDav client at the address http://address/cal/caldav.php/user/home

More details at Installation_Guide_Update_(Feb_2008) including what to do if you have lost you password.

URL Rewriting
If you want to get rid of the "/caldav.php" in the URL or simplify the configuration of iOS devices, this can be done with Lighty's URL rewriting (mod_rewrite) as follows:

Uncomment the line in /etc/lighttpd/modules.conf:


 * 1)  "mod_rewrite",

Add the rewrite rules to the /etc/lighttpd/lighttpd.conf or vhost config file:

url.rewrite-once = (  ## Don't rewrite the root URL. You might want to comment this out if you   # want to use an explicit /index.php for getting to the admin pages.      "^\/$" => "$0",   ## Don't rewrite for .php, stylesheet, script or image.      "^\/.+\.(php|css|js|png|gif|jpg).*" => "$0",   ## Rewrite for ?   #  "^/.well-known(.*)$" => "/caldav.php/.well-known$1",   ## Rewrite rule for iPhone      "^/principals/users(.*)$" => "/caldav.php$1",   ## Rewrite everything else to caldav.php      "^/(.+)" => "/caldav.php/$1" )
 * 1) rewrite URLs for easy configuration of clients, iPhone, etc.

Troubleshooting
Lighttpd logs errors in DAViCal scripts at /var/log/lighttpd/error.log

If you get logs like the following then don't worry, the SQ indiates the 'error' is actually a slow query warning which you should expect using a 32MB 266MHz server.:

2009-04-11 10:44:27: (mod_fastcgi.c.2610) FastCGI-stderr: davical: LOG: calquery: Query: SQ: Error in '/usr/share/davical/inc/caldav-REPORT-calquery.php' on line 268

You may wish to change the time threshold for this error, in /usr/share/awl/inc/PgQuery.php</tt> change the line:

line 336:  var $query_time_warning = 0.3; </tt>

to, say, 2.0 (seconds), although obviously this will need re-modifying at each upgrade! On a normal server the error is more likely to indicate that the database needs 'vacuuming' and you should check the PostgreSQL documentation for how to do this, and how to enable auto-vacuum.