Apache Config

From Davical
Jump to navigationJump to search

Template:Languages Template:TOCright

Modules

The PHP5 module must be enabled.

Virtual Host Installation

For basic virtual host installation see the DAViCal Installation page. This is the recommended way of installing DAViCal since it ensures that the PHP settings for DAViCal are not in conflict with the settings for other applications hosted by the same Apache server.

<VirtualHost 123.4.56.78 >
  DocumentRoot /usr/share/davical/htdocs
  DirectoryIndex index.php
  ServerName davical.example.net
  ServerAlias calendar.example.net
  <Directory /usr/share/davical/htdocs/>
     AllowOverride None
     Order allow,deny
     Allow from all
  </Directory>
  AcceptPathInfo On
  #  You probably don't need to enable any of these sorts of things other than in exceptional
  #  circumstances.  Apart from the include path (which DAViCal will discover if it is anywhere
  #  'normal') they are the default in newer PHP versions. 
  # php_value include_path /usr/share/awl/inc
  # php_value error_reporting "E_ALL & ~E_NOTICE"
  # php_value default_charset "utf-8"
  # php_admin_flag magic_quotes_gpc off
  # php_admin_flag register_globals off
  #
  # If the Suhosin extension is active
  # php_admin_flag suhosin.server.strip off
</VirtualHost>

Note: When using PHP via CGI/FastCGI, "AcceptPathInfo Default" is enough.

For installations in Debian 8 using the repository to install DaviCAL and also using Virtualmin, the above configuration should be used with the following lines (note that the FastCGI lines are missing because of changes made by Virtualmin) to Apache:

# "#1001" should be the uid / guid of the domain owner
SuexecUserGroup "#1001" "#1001"
# Virtualmin specific logs
ErrorLog /var/log/virtualmin/cal.example.com_error_log
CustomLog /var/log/virtualmin/cal.example.com_access_log combined
# the subdomain specific cgi directory
ScriptAlias /cgi-bin/ /home/example/domains/cal.example.com/cgi-bin/
AddType application/x-httpd-php .php
<Directory /home/example/domains/cal.example.com/cgi-bin>
    AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
    Require all granted
</Directory>

Note: Most installations of Debian 8 with Apache 2.4 will likely be using "Require all granted" instead "Allow from all". The Virtualmin install modifies the Apache install so that this will create "403 Forbidden" messages if you do. You must in this case use "Allow from all".

Installation in a Sub Directory

To install in a subdirectory you should not need anything special, except that the path to /caldav.php and so forth will be further down the path. Where you want to make DAViCal available, symlink to the 'htdocs' directory as (e.g.) davical.

Alternatively, if you have root access, you should be able to do something like:

Alias /cal/ /usr/share/davical/htdocs

You will also need to set some PHP settings:

  • Append /usr/share/awl/inc to the include_path
  • Disable magic_quotes_gpc
  • Enable open_basedir (enabled by default, but might be disabled in some circumstances. Note that this is not as simple as 'open_basedir "1"' which you might see listed on some sites.)
  • Optionally disable register_globals (recommended)

This can be done either in the php.ini file or in the Apache config file.

Listening on the Proper Port

As it is preferred to config DAViCal inside a VirtualHost, it is also recommended to make your DAViCal listen on a custom port. If you've set up DAViCal to run on port 8008 don't forget to edit Apache2's ports.conf file to listen on port 8008.

 Listen 8008

Fancy Stuff

URL Rewriting

If you want to get rid of the "/caldav.php" in the URL this can be done with Apache's URL rewriting (mod_rewrite) as follows:

RewriteEngine On

# Not if it's 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.
RewriteCond %{REQUEST_URI} !^/$

# Not if it existing file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

# Everything else gets rewritten to /caldav.php/...
RewriteRule ^(.*)$ /caldav.php/$1  [NC,L]

This means that a URL like this would now work for user2's 'lectures' calendar, for example:

http://calendar.example.net/user2/lectures/

If you're using a virtual host, you'll need to use a recipe like this instead:

 RewriteEngine On
 # Not if it's 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.
 
 RewriteCond %{REQUEST_URI} !^/$
 
 # Not if it explicitly specifies a .php program, stylesheet or image
 # NOTICE THIS IS VERY IMPORTANT IF YOU NEED ACCESS FROM IOS 5 DEVICES
 # since IOS 5 for some reasons insists on prefixing the URL with /caldav.php
 # an refuses to communicate with DAViCal if returned URL's does not contain
 # a URL prefixed with /caldav.php
 RewriteCond %{REQUEST_URI} !\.(php|css|js|png|gif|jpg)
 # Not if it's an existing file
 RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
 RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
 
 # Everything else gets rewritten to /caldav.php/... 
 RewriteRule ^(.*)$ /caldav.php/$1  [NC,L]

because %{REQUEST_FILENAME} evaluates to %{REQUEST_URI} under a VirtualHost context.

  # For clients that still insist on using caldav.php anyway                                                                       
  RewriteCond %{REQUEST_URI} !^/caldav.php/

(using to make AgenDAV 2/git work, which has a different config method than AgenDAV 1 without substitutions).

If you've a virtual host, and DAViCal is not running in the root of that host but under a subdirectory such as /cal/, you'll need something like this. It's assumed the DAViCal installation is at /usr/share/davical (where Debian puts it):

 # Rewrite /cal/USER/CALENDAR to /cal/caldav.php/USER/CALENDAR
 
 # Exclude /cal/ itself
 RewriteCond %{REQUEST_URI} !^/cal$
 RewriteCond %{REQUEST_URI} !^/cal/$
   
 # Exclude existing files such as admin.php and setup.php
 RewriteCond /usr/share/davical/htdocs/$1 !-d
 RewriteCond /usr/share/davical/htdocs/$1 !-f
   
 # Everything else under /cal/ gets rewritten to /cal/caldav.php/...
 # Note the PT flag, it make the Alias directory work
 RewriteRule ^/cal/(.*)$ /cal/caldav.php/$1  [NC,PT]
 
 Alias /cal/images/ /usr/share/davical/htdocs/images/
 Alias /cal /usr/share/davical/htdocs
 
 <Directory /usr/share/davical/htdocs/>
     AllowOverride None
     Order allow,deny
     allow from all
 
     AcceptPathInfo On
     php_value include_path /usr/share/awl/inc
     php_value error_reporting "E_ALL & ~E_NOTICE"
     php_value default_charset "utf-8"
     php_admin_flag magic_quotes_gpc off
     php_admin_flag register_globals off
     # If the Suhosin extension is active
     php_admin_flag suhosin.server.strip off
 </Directory>

ProxyPass

If you want to use ProxyPass for redirecting a location from an apache (for example http://www.yoursite.com/calendars) to another apache with Davical installed, you had to create two ProxyPass rules on the www.yoursite.com virtual host:

ProxyPass /calendars http://davical.yourlan.local/calendars/
ProxyPassReverse /calendars http://davical.yourlan.local/calendars/

and then modify the virtualhost configuration of the davical apache by adding an alias named /calendars pointing to the document root:

  Alias /calendars /usr/share/davical/htdocs

everything should work.

Distinct Logs

You might wish to add the following:

ErrorLog     /var/log/httpd/davical.error_log
TransferLog  /var/log/httpd/davical.access_log

See Also

  • FastCGI for special considerations for running DAViCal with FastCGI
  • FCGI ditto for fcgid