If you’re a big fan of the Mac’s iCal calendaring application like we are, then you will love this addition to your web site. Today we’re going to install PhpiCalendar which does one thing, but does it incredibly well. PhpiCalendar displays picture-perfect web calendars (see inset) of all of your iCal information which can be accessed from anywhere using a web browser. Do you need a .Mac account? Nope. All you need is an ISP-In-A-Box running the Apache Web Server and PHP. You’ll also need to install Webmin to handle the crontab task discussed below unless you’re familiar with the crontab application itself. And we’ve already covered how to password-protect your calendar web site if you want to. Because PhpiCalendar reads .ics calendars (IETF 2445 files), you can also use it to access calendars created with Mozilla Calendar and Sunbird, Novell’s Ximian Evolution, KOrganizer, and WinDates 5.0. Did I mention there are also thousands of free, downloadable .ics calendars at iCalShare that cover every imaginable subject matter: holidays of every flavor, astronomy, TV schedules, DVD release dates, iTunes release dates, sports schedules, band schedules, and on and on. So let’s get started.

We’ll first download the application, and then move it to a folder on your web site. Then we’ll load your existing iCal calendars and test the application. Once everything is working, we’ll add an entry in the crontab file to copy your iCal data over to PhpiCalendar each day at one or more times that you specify.

Downloading PhpiCalendar. PhpiCalendar is one of thousands of applications which are available at no cost on SourceForge.net. Just click here to download the latest 2.0 beta and choose a download site near your location to begin. The application will be copied to your desktop and then automatically decompress into a folder called phpicalendar-2.0b. Let’s rename the folder to something simpler. Just click on the existing folder name and change it to ical.

Moving PhpiCalendar to Your Web Site. Open a Finder window, click on your local hard disk, and then move to the /Library/WebServer/Documents folder. Now click-and-drag the iCal folder on your Desktop into the Documents folder. Now you can access your Web Calendars by going to http://localhost/ical/ or http://yourdomain.com/ical/. Test it now using your web browser. Your own iCal information will not appear, but some sample calendar events will.

Importing iCal Data into PhpiCalendar. In order to import your iCal calendars into PhpiCalendar, we first need to figure out where your iCal data is stored. Using Finder, press Command-F and search for file names on your local hard disk that contain .ics. Click on one of the file matches to display its location which should be something like the following: /yourname/Library/Calendars where yourname is your Mac login ID. Write down what you found, and then open a Terminal windows (Freudian slip?) and switch to root user access: sudo su. Enter your admin password. Now let’s clean out the sample calendars that were distributed with PhpiCalendar and copy your own iCal data into the PhpiCalendar folder:

  • cd /Library/WebServer/Documents/ical/calendars
  • rm Home.ics
  • rm Work.ics
  • cp /Users/yourname/Library/Calendars/*.ics /Library/WebServer/Documents/ical/calendars
  • Now refresh your browser at http://localhost/ical/ and your very own iCal data should now appear in the web calendar. Click on the small icons in the upper right section of the main screen to change from daily to weekly to monthly to yearly views. You can permanently save your preferences by clicking on (you guessed it!) Preferences.

    Automating PhpiCalendar Updates. Because PhpiCalendar operates independently from iCal, we need to automate the process of copying your calendars from iCal each day. We’ll do it with crontab using the Webmin application we installed last week. Make sure Webmin is running (/etc/webmin/start), and then open it with your web browser: http://localhost:10000. Click on the System button and then Scheduled Cron Jobs. Then click Create a new scheduled cron job. Make the following entries in the form and then click the Create button. Leave the default settings unless specified below:

  • Execute cron job asroot
  • Commandcp /Users/yourname/Library/Calendars/*.ics /Library/WebServer/Documents/ical/Calendars (use your actual username for yourname, of course)
  • When to executeTimes and dates shown below
  • Minuteclick on Selected and click on any minute desired
  • Hourclick on Selected and click on any hour desired or Ctrl-Click on several hours to run multiple times each day
  • Days, Months, WeekdaysAll
  • Once you have assured that your calendars are being updated daily, you can silence email advisories by adding > /dev/null 2>&1 to the end of the Command in your cron job. Just click on the job, make the change, and click Save. Check back with us next week for some more terrific applications. Have a great weekend!

    Print Friendly, PDF & Email

    Be Sociable, Share!

    This article has 7 comments

    1. First of all, thanks for this awesome series. I’m a web developer so I’m pretty familiar with a lot of what’s going on here, but it’s still a great quick resource for letting beginners tackle what seems to be an intimidating task. You should write a book!

      Anyway, I’ve never really fiddled around with Macs as web servers until now and am still getting to grips with it. Here’s my question. When I navigate to my Mac from a browser on my PC (XP) in the same network (behind a normal linksys dhcp router) and using the Mac’s IP address, only files in the root directory are viewable. What’s happening is that the server is for some reason redirecting all subdirecties to http://username.local, or the Rendevouz name. This works fine on my Mac, but it doesn’t work from my PC. It just gives me the error, "www.username.local cannot be found. Please check the name and try again." Why is it doing this? Any help would be much appreciated.

    2. It just so happens that I was working on this very problem last night. What you need to do (I believe) is add a forward slash to the end of the subdirectory. So, for example, rather than http://xxx.xxx.xx.xx/ical you enter http://xxx.xxx.xx.xx/ical/
      Try this and see if works. –Doug

    3. Let me second Scott’s comment and mention that this is an incredible set of articles.

      I also second Scott’s problem with the Rendevouz name resolution, I have a similar home network setup. The cruddy way around this is to complete your URLs with a slash, or target the index page itself. So for instance if you wish to access webalizer (as setup in chapter 6, http://mundy.org/blog/index.php?p=30 ), do this from your PC:

      http://macserverip/webalizer/

      OR:

      http://macserverip/webalizer/index.html

      NOT:

      http://macserverip/webalizer

      This is also apparently also an issue when accessing pages from the outside world. I’m not network saavy enough to know what is going on here, but it seems that there should be a config setting to change to fix this.

      Steve

      [WM: There is an Apache setting for this but I’m out of town. Here’s a link that will get you started anyway: http://frenchfragfactory.net/ozh/archives/2004/05/08/apache-and-the-trailing-slash-problem/]

    4. Following your interesting master class, I found a better tool (and easier to install than Webmin) called Cronnix for managing the cron schedules:
      http://h5197.serverkompetenz.net/cronnix/

      [WM: Thanks for the tip. We’re going to cover it in our segment on crontab.]

    5. If these pages were paperback books, I’d have worn them out by now. Thanks so much for getting all this information into one place.

      I’ve been going back and forth between using WebDAV for publishing iCal calendars and using this much more straightforward approach. What are the benefits of each?

    6. This series is great, it puts a whole lot of things right where I need them!. I do have one question: What are the security ramifications of hard linking the files instead of a cronjob? (soft link did not work). It doesn’t look like this app modifies the files, so there’s not much risk of losing all the data. I’d actually rather cron a backup of the .ics files, as the hard link would allow instantaneous updating…

      [WM: Sorry but I don’t understand the question. I’m not the sharpest blade in the drawer so please rephrase your question for me.]

    7. To answer the issue with URL’s getting redirected to machinename.local as referred to in posting number 1, the culprit is the setting for

      UseCanonicalName On

      This can be set to Off in /etc/httpd/httpd.conf

      Another way to handle this if you have a nameserver running is to explicitly set the ServerName variable in the same file

      =Alain