Bwyan.dk / Brian René Jensen

Howto articles and a personal BLog.

Setting up your own cross-platform Calendar server (with iPhone support)

 with 2 comments

Setting up your own cross-platform Calendar server (with iPhone support)

In this howto, I will take you through a step-by-step guide, on how to set up your own calendar sharing/synchronizing service on a computer running either Debian or Ubuntu.

This is especially useful, if you are using more than just a single computer or mobile device in your everyday life, and want to have all your calendars in perfect sync.

This article might seem a little long-winded at a glance, but the set up is actually rather simple. All you need is a computer which is able to run Debian or Ubuntu, and, of course, a network connection (and/or an Internet connection) to be able to access the calendar sharing service from your client computers or devices.

First, a little bit about why I made this guide in the first place…

Why I prefer my calendars digital

I’ve never really been any good at maintaining a handwritten calendar.

Sure, I’ve tried having one, but it’s simply too big and unhandy to carry around with you all the time, and that’s exactly where you need it the most. The stupid thing always ends up lying under a bunch of papers and CD’s in a corner somewhere, only to be found when I don’t really need it. Usually while cleaning.

Chandler calendar server and iPhone 3.0 issues

I’ve been running my own Ubuntu server for quite a while now, and a couple of years ago, I decided to try and install a calendar synchronizing service on it.

I went ahead and found a project called “Chandler”. It’s an open source calendar server, written in Java. It uses a well known and standardized protocol, often used for calendar sharing, called CalDAV. It has a neat web interface and it’s very stable in my experience.

In this way, I was now able to access several different calendars from a single account on my calendar server. CalDAV client programs are available for Windows, OS X, Linux and on a load of different mobile devices, so regardless of which operating system I was using, I could always access my all calendars (in perfect sync, I might add).

This sure made things allot easier for me. Yet, I had never tried setting up my calendars on a mobile device.

As you might have guessed from the title, I recently bought an iPhone, and last year, Apple released their much anticipated 3.0 firmware upgrade. And while everyone else was going on about MMS, improved chat og real GPS featues, the one thing that I was extremely happy about, was that the iPhone now also supported the CalDAV protocol.

After installing the new 3.0 firmware, I rushed to the settings menu and tried to set up my Chandler calendar account. The account was installed without any hiccups, and I was now able to see all the entries that I had previously created from my computer, with either iCal or the web client.

My excitement didn’t last very long though, as I soon discovered that any entries I tried to create from my iPhone, only displayed on the iPhone itself. Synchronization back to the server seemed broken on the iPhone.

Why I switched to the DAViCal calendar server

Then I found DAViCal. Another CalDAV server, written in PHP.

DAViCal has no client web interface to add and manage entries, but it still supports all my CalDAV compatible clients. It’s also allot faster than Chandler, since it’s not running on Java.

After installing DAViCal and migrating all my calendars from Chandler, I added my newly created DAViCal account to my Mac Pro’s iCal application, and in my iPhone’s settings menu…

And voilà! Instant syncing in both directions!

How to set up DAViCal on a Debian server

I made this howto, simply because I spent too much time trying to figure out DAViCal’s own documentation on how to install it. I had to visit allot of forums and google around some, to be able to get everything working. My hope is that others will have an easier time setting it up, by following this guide.

We are going to install a number of different things on our system, in order to get DAViCal working.

Using this howto to configure DAViCal, the following software is going to be installed on your system.

  • Apache (version 1.3.x or 2.x.x)
  • PHP5 (version 5.0 or greater)
  • PHP5 extension for Apache
  • Andrew’s Web Libraries – PHP Utility Libraries (libawl-php)
  • PostgreSQL (version 8.1 or greater)

DAViCal is written in PHP, and needs to run within a web service with PHP support and have access to a PostgreSQL database, to store all the CalDAV accounts and entries. There are many possible configurations on how to achieve this, even with other distributions than Ubuntu or Debian and with other web services than Apache version 2. However, I am not going to cover those in this howto.

Prerequisites for this howto

I am currently using Debian 5.03 to install DAViCal, but I’m pretty sure that any recent versions of Debian and Ubuntu, should install in the exact same way.

If you run into trouble with any of the configuration steps in this howto, please leave a comment, and I will try to help out as much as I can.

I am going to assume that you are using either a Debian or an Ubuntu distribution, and that it is already installed and running on your computer. I am also going to assume that you have the “sudo” package installed, and that you have super user privileges on your system. (The “sudo” package needs to be installed and configured manually in some versions of Debian.)

In the making of this howto, I was using the following Debian packages.

  • Apache (version 2.2.9)
  • PHP5 (version 5.2.6-1+lenny4)
  • PHP5 extension for Apache (version 5.2.6.dfsg.1-1+lenny4)
  • Andrew’s Web Libraries (version 0.38-0)
  • PostgreSQL (8.3.8-0lenny1)

Using the examples in the following chapters, might install different versions of these packages.

Installing Apache with PHP5 support and Andrew’s Web Libraries

First, you need to install and configure the Apache service with PHP5 support. Install the required packages, like this:

sudo apt-get install apache2 php5 libapache2-mod-php5

Once the packages are installed, PHP5 should have configured itself with Apache automatically.

Next, you need to install Andrew’s Web Libraries.

sudo apt-get install libawl-php

It might be a good idea to restart the Apache service manually, to ensure that the PHP5 extension and Andrew’s Web Libraries are loaded properly.

/etc/init.d/apache2 restart

You can test your PHP5 configuration, by creating a PHP file with the following contents, and placing it in Apache’s “document root”. (As “/var/www/index.php”)

<?
phpphpinfo();
?>

Now, visit your website, by going to “http://ip.address.of.server/index.php”.

If you see a lot of information about your PHP configuration, your Apache service should be configured correctly with the PHP5 extension.

Installing DAViCal

To install DAViCal, you have to add the DAViCal repository.

You can easily add the repository to the bottom of your “sources.list” file, by executing this command.

sudo echo “deb http://debian.mcmillan.net.nz/debian lenny awm” >> /etc/apt/sources.list

The repository is signed with Andrew McMillan’s public key, which means that you have to add it to your system, in order to be able to fetch software from it.

Execute the following command, to add the public key to your system.

sudo apt-key advanced –keyserver subkeys.pgp.net –recv-keys F6E0FA5CF0307507BB23A512EAFCFEBF8FEB8EBF

You might run into problems, trying to install the public key, if it should have changed since I last revised this howto. In this case, you should go to the official DAViCAL Installation Page at davical.org. Here you should be able to find the latest version of the public key, and install that instead.

If the key installs without any errors, we should now be able to update the repository and install DAViCal.

sudo apt-get update && sudo apt-get install davical

You should allow any extra packages to be installed, if prompted.

Installing the PostgreSQL service and setting up the database

You should now install the PostgreSQl service.

sudo apt-get install postgresql

On my system, the above command automatically fetched and installed the postgresql-8.3 package.

After installing the PostgreSQL service, you have to set up the database. First, you need to add a user account with minimum privileges, to the main PostgreSQL database. DAViCal needs this user, to be able to connect to the database from the Apache service. You should do this, by first logging in as the user “postgres”, and then creating the user “davical_app”, like this.

sudo su postgres
createuser –no-createdb –no-createrole davical_app
Shall the new role be a superuser? (y/n) n

Now, staying logged in as the “postgres” user, you need to setup the database that DAViCal is going to use. Do this, by executing a script that got installed along with DAViCal.

It is located here: “/usr/share/davical/dba/create-database.sh”, and executes like this. (Keep in mind that you have to be logged in as the “postgres” user.)

/usr/share/davical/dba/create-database.sh
Supported locales updated.
CalDAV functions updated.
RRULE functions updated.
Database permissions updated.
NOTE ====
* You will need to edit the PostgreSQL pg_hba.conf to allow the ‘davical_dba’ database user access to the ‘davical’ database. *
The password for the ‘admin’ user has been set to ‘1A84K1aB‘”
Thanks for trying DAViCal!
Check in /usr/share/doc/davical/examples/ for some configuration examples.
For help, visit #davical on irc.oftc.net.

It’s very important that you jolt down the password for the “admin” account, from your own output of the last command (not from my example above). You are going to need it in the end of this howto.

Now you need to edit the file “pg_hba.conf”, in order to give DAViCal access to the database, as the “davical_app” user, which we created earlier. I found the file in “/etc/postgresql/8.3/main/”, but your file might be placed in a different directory, depending on which version of the PostgreSQL package you installed earlier.

Add the following line in the beginning/top of your “pg_hba.conf” file.

local davical davical_app trust

This means that anyone on the local computer, will have rights to connect to the DAViCal database as the ‘davical_app’ user. If you you have untrusted local users on your system, you might want to reconsider the above configuration, and possibly find a more secure solution.

Finally, you need to restart the PostgreSQL service, to make the changes come into effect.

sudo /etc/init.d/postgresql-8.3 restart

Again, the above command might be a little different for you, if you installed another version of the PostgreSQL package earlier.

Configuring Apache and DAViCal

In this step, we are going to configure Apache to handle a “virtual host” for displaying DAViCal’s web interface. This configuration can also be achieved in many different ways, but I’m going to keep it as simple as possible, to avoid too much confusion for those unfamiliar with “virtual hosts”.

You should keep in mind, however, that if you are already hosting other websites with Apache, you might want to configure this virtual host in another manner. This configuration could possibly make all or some of your other hosted websites unavailable.

First, you need to add a link to the DAViCal PHP files in Apache’s “document root” directory (“/var/www”). This is done like this.

sudo ln -s /usr/share/davical/htdocs /var/www/davical

Next, you need to configure Apache to display the DAViCal PHP files as the default website, by adding a “virtual host”.

If your Apache service is currently not hosting any other websites, you should be able to configure your “/etc/apache2/sites-available/default” file, like this:

<VirtualHost *:80>
DocumentRoot /var/www/davical
DirectoryIndex index.php
Alias /images/ /var/www/davical/images/
<Directory /var/www/davical/>
AllowOverride None
Order allow,deny
Allow from all
</Directory>
php_value include_path /usr/share/awl/inc
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value open_basedir 1
php_value error_reporting “E_ALL & ~E_NOTICE”
php_value default_charset “utf-8″
</VirtualHost>

Now restart the Apache service, to load the new website.

sudo /etc/init.d/apache2 restart

Now, if everything is set up and running as it should be, you should now be able to access the DAViCal web interface at “http://ip.address.of.server“.

There is one last step to be taken, before everything is up and running, though.

When accessing your DAViCal’s webinterface, you should see a page displaying something similar to this.

This means that DAViCal is expecting to find a specific configuration file, based on which IP address or domain name you are using to access DAViCal’s web interface.

In the example above, I am trying to access the web interface with the local IP-address of my server which, in my case, is “192.168.1.161“.

The DAViCal web interface is thus telling me to make a DAViCAL configuration file, which is to be created as “/etc/davical/192.168.1.161-conf.php”, with the following content.

<?php
// $c->domain_name = ‘davical.example.com’;
// $c->sysabbr = ‘davical’;
// $c->system_name = ‘DAViCal CalDAV Server’;

$c->admin_email = ‘admin@example.com’;
$c->pg_connect[] = ‘dbname=davical user=davical_app’;
?>

The important thing to understand here, is that this file needs to be individually created, based on the IP-address and/or domain name of your server.

DAViCal’s web interface will always notify you, if a configuration file is missing, and it will even tell you how to create it, so you should have no problems configuring this part on your own.

Once you have created this configuration file correctly, you should be able to see the login screen.

Now all you need to do, is login with you admin account. (Which you wrote down earlier, setting up the database.)

Once you have logged in, the first thing you should do, would be to change you admin password to something else.

You should then be able to create a new user account, which also automatically creates a standard “home” calendar for your new user.

In the next chapter, I will show you how to add your new DAViCal account with a number of different CalDAV clients. (Including the iPhone.)

Adding your DAViCal accounts to different CalDAV clients

In this chapter, I will show you how to set up your DAViCal accounts on a number of different CalDAV clients.

The iPhone

Setting up your new DAViCal account on the iPhone is fairly simple. You just have to know how to add the server address, which took some time for me to figure out. If you add it incorrectly, you might end up having only a single calendar on your account displayed.

Go to the “Settings” application and choose “Mail, Contacts, Calendars”. You should then select “Add Account…” and choose “Other”.

Select “Add CalDAV Account” and fill in the information for your DAViCal server, like this:

Keep in mind that “http://ip:80/caldav.php/user” should be entered correctly to reflect your set up, of course.

Mac OS X (iCal)

Open up iCal and go the to Preferences menu.

Select the “Accounts” tab and click the “+” button in the bottom of the window and fill in your account information like this:

Keep in mind that “http://ip:80/caldav.php/user” should be entered correctly to reflect your set up, of course.

Windows

Will be added soon…

Linux (Evolution)

Evolition doesn’t seem to be able to add an entire account all at once. You will have to add each of your calendars in your account, individually.

First you need to go to the DAViCal web interface and log in with your account information.

Go to the “User” tab and scroll all the way down to the bottom of the page. There you will find the “collection ID’s” of your individual calendars. The long string of code in the end of each collection, is the “collection ID”. You should copy that code, to use it in Evolution in the next step.

Fire up Evolution and go to the calendar view. Right click on an empty space in the calendar selection window on the left. Choose “New Calendar” and fill out the fields like this:

Keep in mind that “http://ip:80/caldav.php/user/collectionid” should be entered correctly to reflect your set up, of course.



Share this page, using your social network:

  • Facebook
  • Twitter
  • LinkedIn
  • MySpace
  • StumbleUpon
  • Digg
  • Slashdot
  • Netvibes
  • RSS
  • email

Written by Brian René Jensen on:

5. January, 2010 @ 04:55

Last update is on:

7. March, 2010 @ 17:08

2 Responses to 'Setting up your own cross-platform Calendar server (with iPhone support)'

Subscribe to comments with RSS or TrackBack to 'Setting up your own cross-platform Calendar server (with iPhone support)'.

  1. Thank you! Synchronisation works both ways with the iPhone, but I cannot accept or create an invitation (I can see an invitation, but cannot take any action on it). Do you have an idea on how to resolve this?

    Marcel

    27 Mar 10 at 08:31

  2. Hi Marcel.

    I currently do not use invitations in my calendar, so I’m not sure really.

    I didn’t even know that you could have invitations inside a caldav calendar.

    Are these invitations something you would receive through your e-mail application that then goes into your calendars?

Leave a Reply