PHP iCalendar

From MTU LUG Wiki
Jump to navigation Jump to search

PHP iCalendar is a SourceForge project that can be found here: http://sourceforge.net/projects/phpicalendar/. It is a collection of php pages that uses .ics (RFC 2445) files (like those from iCalendar on OS X) to generate a web page containing your schedule on the fly. Since it's PHP, it is platform independent, I'm only going to cover OS X though, since that's what I initially set it up on.

An example of this is my schedule. There are a number of ways to give the php pages access to the calendar files. I'll only cover one method here, and that is setting up a cron script to copy the files to the proper directory. This method assumes that you have not edited any of your system files, if you have, be on the lookout with the changes you have made fresh in your mind.

Download and install

The first thing that needs to be done though, is to download and untar the project into your Sites folder. After this, you need to enable Personal Web Sharing under the Sharing section of System Preferences.

Apache

Then, edit /etc/httpd/httpd.conf and make the following changes:

Uncomment the following lines:

LoadModule php4_module
libexec/httpd/libphp4.so
AddModule mod_php4.c

After the line that says: AddType application/xtar .tgz add the following lines

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Find and replace:

<IfModule mod_dir.c>
DirectoryIndex index.html
</IfModule>

with:

<IfModule mod_dir.c>
DirectoryIndex index.html index.php
</IfModule>

Then, ina terminal type:

sudo apachectl graceful 

to restart the webserver and allow the changes that were made to take effect.

Configuring

Next, PHP iCalendar needs to be configured. If you don't want to change anything, then don't. If you do, the file is config.inc.php in your phpicalendar folder. It is pretty well documented and things are easy to figure out.

Updating the calendars used

Now comes the important part: getting your ical files into the directory for PHP iCalendar to use them. To do this, a crontab is going to be added that will copy over the files every five minutes. While not as nice as the instantaneous method WebDAV allows, changes are available reasonably quickly. You will need to edit /etc/crontab to set up the automation of thet script that will be written. The following will set up the calendar copying.

sudo vim /etc/crontab

Add the following line into the section topped by minute, hour, mday, etc. where each thing goes into a seperate column. Replace kyle with your username.

*/5    *     *    *    *     kyle     calendar_copy

2) Save and close the file.

3) Create a new file called calendar_copy

sudo vim /usr/sbin/calendar_copy

add the following text to it, while replacing kyle with your username.

cp /Users/kyle/Library/Calendars/* /Users/kyle/Sites/phpicalendar/calendars/.

4) Change the permissions on the file to be executable:

sudo chmod 755 /usr/sbin/calendar_copy

Wrap-up

That's all there is to it. Your site will be available at: http://your-host-name/~your-user-name/phpicalendar/

Other methods of setting this up include: Using a webdav server or publishing to the php script included in the project, if you wish to do those, check google.