Created by magical gnomes!
DAViCal on CentOS 6 HOWTO
helping maintain an illusion of privacy in an increasingly nosy society

Magical gnomes present: Calendaring for All Platforms!

With the extraordinary amount of personal data and patterns harvested by the likes of Google and friends, you, like me, may be interested in trying to mitigate your dependency on such large behemoths in an (admittedly futile) attempt to preserve some illusion of privacy.

This article covers setting up a DAViCal server on a CentOS 6 box, as well as getting it to work with Thunderbird's Lightning plugin, Android with aCalDAV on F-Droid, and possibly Apple. But if you're using Apple, you probably aren't interested in setting up your own calendar server. Because that's complicated.

I'll start with a caveat: I don't like putting things in system directories when I don't have to. Especially if they have to be owned by root. It's largely an irrational fear, but as a result these instructions include modifications to get DAViCal up and running from an unprivileged DocumentRoot.

I recommend starting by creating a user named calendar. As root:
$ useradd -g users calendar

CentOS Packages

There are dependencies here, as you might expect. I assume you already have a functioning Apache setup with PHP. If not, go find some other howto like this one, but you can skip the part about MySQL, because DAViCal uses PostgreSQL instead. Yes, I know, all of my stuff uses MySQL too. Until now. Go cry to your Mom.

Anyway, I found I needed to install the following additional packages:
phpdoc postgresql-server perl-DBD-Pg perl-YAML php-pgsql

$ yum install phpdoc postgresql-server perl-DBD-Pg perl-YAML php-pgsql

Maybe you'll find you need more.

Get AWL and DAViCal

  • Get the latest AWL release here.
  • Ungzip/tar it.
  • Move the base directory to a directory named "awl".
If you're doing this as the calendar user mentioned above, then:
$ su - calendar
$ lynx # Or whatever, just get the tarball linked to by the URL above
$ tar -zxvf awl*.gz
$ mv awl.git awl
  • Download the latest DAViCal release here.
  • Ungzip/tar it.
  • Move the base directory to a directory named "davical".
Still as the calendar user:
$ lynx # Blah
$ tar -zxvf davical
$ mv davical.git davical

That's it. This part is easy. Actually, this whole thing is easy.

Populating the Database

  • Run the script
  • Secure postgres and the davical accounts
I found the easiest (read: laziest for me, at least) way to get the database populated was to simply run the script as the postgres user, which by default lets you do whatever you want. It's insecure. You're trusting someone else. But then again, you haven't audited every line of code in your OS have you? So much trust...
$ cd davical/dba
$ su postgres -c ./ # Maybe prepend sudo, if you like it that way

If you have problems, bash your head against the wall for a while and fix them. You need to have a fully populated database. Also, the script should spit out an admin password. Hold onto it.

Next we need to setup postgres so that davical can actually connect to it. There are two ways to do this, the stupid way and the secure way. We're only going to do the secure way.

Connect to postgres and set a password for both the davical_app and davical_dba users:
$ su - postgres
$ psql
psql (8.4.20)
Type "help" for help.

postgres=# alter user davical_app with password 'something';
postgres=# alter user davical_dba with password 'something';

Next, edit /var/lib/pgsql/data/pg_hba.conf and change every occurrence of ident to md5. This forces the use of passwords. You should probably set a password for the postgres database user before you do this:
postgres=# alter user postgres with password 'somethingelse';
postgres=# \q

Alternatively, you could add an explicit line to preserve the postgres user's authentication mechanism as ident. Or explicitly require md5 for only the davical users.

If you already have a functioning postgres installation, presumably you know what you're doing.

Configuring DAViCal

  • Create the configuration file
  • Set the connect password
  • Set other configuration parameters
  • Disable auto_schedule for lightning
Since we're doing this locally, copy the example configuration file to config.php and edit it:
$ cd davical/config
$ cp example-config.php config.php

Edit config.php and change the connect line to:
$c->pg_connect[] = "dbname=davical user=davical_app password=something";

Set your system_name.

Assuming you're going to use Thunderbird's Lightning plugin, you want to also disable auto_schedule. Otherwise your log files will get filled up with backtraces like this:
[Tue Dec 02 07:55:46 2014] [error] [client] davical: BUG: :Exists true
[Tue Dec 02 07:55:46 2014] [error] [client] ================= Stack Trace ===================
[Tue Dec 02 07:55:46 2014] [error] [client] ===> /home/calendar/davical/htdocs/caldav.php[135] calls include()
[Tue Dec 02 07:55:46 2014] [error] [client] ===> /home/calendar/davical/inc/caldav-DELETE.php[77] calls do_scheduling_for_delete()
[Tue Dec 02 07:55:46 2014] [error] [client] ===> /home/calendar/davical/inc/schedule-functions.php[32] calls DAVResource->GetProperty()

Nobody wants that. Add this line to config.php:
$c->enable_auto_schedule = false:
It doesn't matter where you put it.

Setup a Vhost or Alias for Apache

You can create your own vhost with the DocumentRoot set to the htdocs subdirectory in the DAViCal installation, or you can just add an alias to an existing vhost (preferably one that uses SSL). Eg:
Alias /caldav /home/calendar/davical/htdocs

If you don't know how to do this, read your Apache docs.

Now you should be able to visit the corresponding URL and login using the admin password that was generated earlier. You know, the one you were supposed to remember. If you're having problems, best of luck to you. You're welcome to send me an email. I might even be helpful. If you run into problems and fix them yourself and think they're worth mentioning on here, I'd be happy to add to this along with proper attribution of credit as well. Just let me know.

Create a Calendar

Assuming you're able to login, go to User Functions and Create New Principal. Fill out the appropriate fields, and this will create a user and associated calendar.

You can then hit User Functions->List Users, click the ID, scroll to the bottom where the Principal Collections are, click the ID for the calendar, and if you desire under Collection Grants you can allow other principals/users to access the calendar in question. There are other more complicated ways to do this with groups and things, but for my setup it's not worth the effort.

Configure Lightning

If you're using the Lightning Calendar plugin for Mozilla Thunderbird, you can easily add your newly setup collection above.

Simply hit File->New->Calendar.
Choose On the Network
Format should be CalDAV
and use https://yourserver/caldav/caldav.php/username/calendar/, replacing yourserver and username appropriately, as the location.


Configure aCalDAV

A similar procedure can be followed for aCalDAV available on the F-Droid market for the Android phone.

Final Notes

This should work for anything that supports the CalDav interface. Jon Rexeisen has confirmed that this includes Apple products as well. Feel free to email Jeff if you have questions, find a mistake, or have suggestions for improvement.