tips for running ColdFusion on Mac os X (Leopard)

My home computer has been a Mac for some time now, although I still use a PC at work. This means that I’ve been switching back and forth between dev environments, and have learned a wack of things about getting ColdFusion 8 set up on a Mac. Some of these are more general “dev on a mac” tips, but apply, so here goes:

  1. Run ColdFusion from the command line:
    cd /Applications/JRun4
    sudo start cfuson

    Leave the terminal window open, and you’ve got a great debugger and view into what’s going on behind the scenes. Also – always run ColdFusion as root, or you’ll get the occasional odd error, to do with permissioning.

  2. Set up Virtual hosts: this is a general local-dev tip, but I find it even more helpful in the Mac/Apache environment than in the PC environment. You’ll need to edit your hosts file (found in /private/etc), and add in an entry per site, in the following format (where [sitename] is the name of your site):
    127.0.0.1 [sitename].local

    which will allow you to browse to http://[sitename].local/ to view your site – much nicer than http://localhost/[sitename]/.

  3. Configure Apache to support Virtual hosts: To this to allow yourself to create aliases, custom 404 errors, etc. This is done in the following way:
    1. Edit httpd.conf. You’re looking for line (somewhere near the bottom, that looks like:
      # Virtual hosts
      #Include /private/etc/apache2/extra/httpd-vhosts.conf

      Edit the second line to remove the #, so it looks like:

      # Virtual hosts
      Include /private/etc/apache2/extra/httpd-vhosts.conf
    2. Edit the httpd-vhosts.conf file. In there, you’ll find a sample virtual host. Delete, or comment that out, then add the following line:
      Include /private/etc/apache2/vhosts/*.conf

      Then save and close the file.

    3. Create a new folder in /private/etc/apache2 called “vhosts”, then create a new file called [sitename].conf.
    4. Open [sitename].conf, and put in the following:
      <VirtualHost *:80>
          ServerAdmin webmaster@[sitename].local
          DocumentRoot "/Path/to/[sitename]"
          ServerName [sitename].local
          ErrorLog "/private/var/log/apache2/[sitename]-error_log"
          CustomLog "/private/var/log/apache2/[sitename]-access_log" common
          ErrorDocument 404 "/404Custom.cfm"
          DirectoryIndex index.cfm index.html index.htm
         <Directory /Path/to/[sitename]>
          Options Indexes FollowSymLinks
          AllowOverride All
          Order allow,deny
          Allow from all
          </Directory>
      Alias /cfide /Library/WebServer/Documents/CFIDE
      </VirtualHost>
    5. If you need to add other aliases, do so in there. Then save the file.
    6. restart apache, with the following command:
      sudo apachectl restart
    7. You’re done! You should now have a happily running ColdFusion site on your local box.
  4. Set up Custom 404 handlers/stubless folders: This is all about getting mod_rewrite working. To do this, open httpd.conf and ensure that the mod_rewrite module is NOT commented out. Then, in your site folder, create a .htaccess file, with the following in it:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) /404Custom.cfm?%{REQUEST_URI}

    You can now use your 404Custom.cfm script to redirect and handle those 404s however you like.

  5. Avoid Lazy coding: If you were like me, you likely had some code that referenced cgi.path_info to figure out where a script was. This won’t work on Mac OS X. Fortunately, the cgi.path_translated works just fine – only remember that this includes the file. Likewise, if you’re directory crawling, *nix paths use “/” to separate folders, whereas windows paths use “” it’s super easy to store a variable for if/when you’re doing file & directory management work, and will make your code that much more portable. Plus, you’ll likely avoid the 8-odd hours of frustration I had when I first switched, and didn’t realize that I had left some windows-specific pathing in some old code.
  6. Tell me how to get cfchart working: I don’t know what the issue is here, and I’m sure it’s something I’ve done, but I cannot seem to get flash-based cfcharts to run on Mac OS X – if you have, please tell me, it would make me very happy.

Happy Coding!

One Reply to “tips for running ColdFusion on Mac os X (Leopard)”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: