From SemarkIT
Jump to: navigation, search


What is DAViCal

DAViCal is a server for calendar sharing. It is an implementation of the CalDAV protocol which is designed for storing calendaring resources (in iCalendar format) on a remote shared server.

An increasing number of calendar clients support the maintenance of shared remote calendars through CalDAV including Mozilla Calendar (Sunbird/Lightning), Evolution, Mulberry, Chandler, and various other closed-source products such as Apple's iCal, iPhone and Microsoft Outlook.



  • is Free Software licensed under the General Public License.
  • uses an SQL database for storage of event data
  • supports backward-compatible access via WebDAV in read-only or read-write mode (not recommended)
  • is committed to inter-operation with the widest possible CalDAV client software.

DAViCal supports basic delegation of read/write access among calendar users, multiple users or clients reading and writing the same calendar entries over time, and scheduling of meetings with free/busy time displayed.

Install DAViCal

apt-get install davical postgresql apache2 php5 libapache2-mod-php5 php5-cgi php5-cli php5-common php5-curl php5-mcrypt \
php5-gd php5-geoip php5-gmp php5-ldap php5-mysql php5-pgsql php5-suhosin libapache-mod-security
a2enmod ssl && a2ensite default-ssl

On Debian Etch or later the following will be met if you use the version from the repo


DAViCal depends on a number of things. Firstly, it depends on Andrew's Web Libraries (AWL) which is a set of useful PHP functions and objects written by Andrew McMillan over a number of years.

The following other software is also needed:

  • A webserver which can run PHP (however this documentation assumes Apache 2.2 or later)
  • PHP: 5.1 or greater
  • PostgreSQL: 8.1 or greater

The PostgreSQL database may be installed on a server other than the web server, and that kind of situation is recommended if you want to increase the security or scalability of your installation.

In this guide I will describe howto run DAViCal within the web root of some other application, but since the CalDAV store takes over a significant amount of path hierarchy, it can be easier to run it in it's own virtual host. There are instructions on the DAViCal Wiki about doing this, as well as other fancy tricks such as configuring URL rewriting in order to shorten the path.

Database Setup

Connecting to the Database

Before your database has been created, you should edit your pg_hba.conf file (in /etc/postgresql/8.x/main/pg_hba.conf on Debian or derivatives) in order to grant access to the database for the 'davical_dba' user that will be created to 'own' the database and tables, and also for the 'davical_app' user which will be created for the web application to connect as.

In a simple installation, where you do not have untrusted users on your database server, and your database is on the same computer as the web server, the following lines (at the very top of the pg_hba.conf file) should be enough:

local   davical    davical_app   trust
local   davical    davical_dba   trust

This means that anyone on the local computer (including the web application) will have rights to connect to the DAViCal database as the 'davical_app' or 'davical_dba' user. It will not allow remote access, or access as any user other than 'davical_app' or 'davical_dba'.

If you want to connect to the database over TCP/IP from your webserver on '' (e.g. rather than unix sockets which will only work for access from the local machine), the lines in the pg_hba.conf file should look something like:

host davical davical_app trust
host davical davical_dba trust

If you want greater security, or if you want to have the database on a different server, you should read the PostgreSQL documentation on pg_hba.conf for the version you are using.

NB. It can be necessary to allow all hosts to connect to your database server in postgresql.conf also.

Once you have changed the pg_hba.conf file you will need to reload or restart the PostgreSQL process for the change to come into effect.

Creating and Building the Database

To create the database itself, run the script:


Note that this script calls the AWL database scripts as part of itself and it expects them to be located in /usr/share/awl/dba which might be a reasonable place, but it might not be where you have put them.

This script expects to be running as a user who has rights to create a new database, so you may need to do this as the "postgres" user, for example:

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

Apache Configuration

nano /etc/apache2/sites-available/default
<Location /davical>
    RewriteEngine On
    rewriteCond %{SERVER_PORT} 80
    rewriteRule ^(.*)$ https://www.example.local/davical [R,L]
ln -s /usr/share/davical/htdocs/ /var/www/davical

Configure DAViCal

For more configurations settings please see http://wiki.davical.org/w/Configuration_settings

nano /etc/davical/www.example.local-conf.php
//  $c->domain_name = "calendar.example.net";
//  $c->sysabbr     = 'DAViCal';
//  $c->admin_email = 'admin@example.net';
//  $c->system_name = "Example DAViCal Server";
//  $c->enable_row_linking = true;

 $c->system_name = "DAViCal CalDAV Server";
 $c->admin_email ='webmaster@example.local';
 $c->pg_connect[] = 'host=db.example.local dbname=davical port=5432 user=davical_dba';
 $c->enable_row_linking = true;


Just add the following to you /etc/davical/www.example.local-conf.php file. I assume that you already have you apache linked to LDAP for this to work.

$c->authenticate_hook['config'] = array(
    'host' => 'ldap.example.local',
    'port' => '389',
    // 'startTLS' => true, // enable this if your LDAP server wants TLS
    'filterUsers' => 'objectclass=*',    // we need this to successfully search users
    'baseDNUsers' => 'ou=Users,dc=example,dc=local',  // most orgs have more fields
    'protocolVersion' => 3, 
    'mapping_field' => array("username" => "uid",
                             "updated" => "modifyTimestamp",
                             "fullname" => "cn" ,  // "Common Name" 
                             // "user_no" => "uidNumber" ,  // set DAViCal user no to match Unix uid from LDAP, may cause sql_from_object problems if these user ids do not actually match...
                             "email" => "mail"
                             ), //used to create the user based on his LDAP properties
    'format_updated'=> array('Y' => array(0,4),
                             'm' => array(4,2),
                             'd' => array(6,2),
                             'H' => array(8,2),
                             'M' => array(10,2),
                             'S' => array(12,2)), // map LDAP "modifyTimestamp" field to SQL "updated" field

Restart all changed services

/etc/init.d/apache2 restart && /etc/init.d/postgresql restart