Washington Apple Pi

A Community of Apple iPad, iPhone and Mac Users

ColdFusion MX 7.01 for Mac OS X

By Steve Seaquist, long-time WAP member

Washington Apple Pi Journal, reprint information

Macromedia’s ColdFusion MX 7.01, code named “Merrimack,” is the first version ever with a Macintosh installer. ColdFusion users with Macs have been clamoring for this for years, so the code name is a pun.

Macromedia released it with little or no fanfare. In part, I’m writing to rectify that. This is a major step forward for the Mac as a Web development platform, and Mac developers really ought to know about it.

What is ColdFusion?

ColdFusion (CF) is a Web programming language and a server to process that language. It makes creating dynamic Web pages really, really easy. It’s a commercial product, so it costs money for a licensed version, just as Apple’s WebObjects does. But the Developer Edition is free, so you can learn it for free. The Developer Edition is restricted to serving pages to only two IP addresses, but other than that, it’s the full, commercial package.

As of ColdFusion “MX” (version 6 and higher), it runs on top of a Java 2 Enterprise Edition (J2EE) server. If you don’t have a J2EE server, don’t worry. The installer will also install the Macromedia J2EE server called JRun, if you like. In the background, your ColdFusion source code is pre-compiled into Java source code, which is then compiled into Java class files, which then run on the J2EE server. So you enjoy all the power and scalability of J2EE, without having to learn Java.

ColdFusion source code is called ColdFusion Markup Language (CFML), because it uses the same tag structure as HTML. Your files would typically have the “.cfm” suffix, which tells the Mac’s Apache Web server to let CF and J2EE process the file. Perhaps you’d like an example, just to see what CFML looks like:

<cfif Form.EMailAddr is not "">

<cfmail to="#Form.EMailAddr#" subject="Thanks for your order">

We have just received your order of #Form.Purchases#.

Thanks for shopping with us. Your credit card will not be billed

until your item(s) ship, at which time you will receive another

e-mail with the tracking number.

</cfmail>

</cfif>

Have you ever bought something on Amazon, and within a minute, you received an e-mail confirming your order? Clearly it was some sort of automatic response, but how did they do it? Well, now you know. They used a Web programming language that allows automatic processes to send e-mails, as in this CFML example.

Note that the CFML tags all begin with “<cf…”. This allows ColdFusion to know which tags are CFML (and therefore require special processing) and which are HTML (and therefore don’t). Also note that the syntax is just as easy as HTML. In fact, if you know HTML, you can probably read what this CFML example does: “If the user entered something in the Web form element called EMailAddr, send this e-mail to that address.”

Installation

If you don’t have a lot of memory on your Mac, you’ll probably want to skip the Installation and Initial Configuration parts of this article. ColdFusion runs as a server, and requires a minimum of two other servers running at the same time (Web and J2EE), and that gobbles up memory. Of course, all of the usual caveats apply: “Your mileage may vary,” “Not responsible for any problems you may encounter,” “If you have a problem, you’re on your own,” etc.

I installed 7.01 on the first weekend of November. It was a no-brainer, an extremely easy install. If you’ve installed CF on Windows or Unix, you already know how. It’s the same installer, with the same questions and the same pretty pictures to keep you from getting bored during the file copying part. As with any Macromedia product installer, just keep clicking the Next buttons, unless you want to do something different.

First, download the installer from http://www.macromedia.com/downloads/ > Products By Category > ColdFusion MX 7 > Try. You’ll have to register with Macromedia if you haven’t already registered, or log in if you have.

After downloading the installer, but before running it, go to System Preferences > Internet & Network > Sharing and turn on Personal Web Sharing (if you don’t already have it on). This fires up the Apache Web server that is part of Mac OS X.

[To configure Apache to serve up index.cfm files when a directory is requested, you may have to edit the /etc/httpd/httpd.conf file. Basically, every DirectoryIndex line in that file has to have index.cfm added to it. The CFMX 7.01 installation did this on my system, but only to the one DirectoryIndex line I don’t use (the one for PHP users)! The line I had to edit said “DirectoryIndex index.html”. I changed it to say “DirectoryIndex index.cfm index.html”, because I wanted index.cfm files to have priority over index.html files. Note that the file name list is space delimited. It’s outside the scope of this discussion to teach you how to edit Unix files with vi or the emacs editor, but I recommend the Nirvana Editor (nedit) for X11 (available for free from http://www.nedit.org/). It’s the most Mac-like Unix text editor. Most of the keyboard shortcuts are the same as the Mac, except that you use the control key instead of the command key. Of course, you should make a backup before you edit httpd.conf, in case you mess it up. Finally, you go to Apple Menu > System Preferences > Internet & Network > Sharing > Services > Personal Web Sharing, turn it off, and turn it back on again. This causes Apache to re-read the new httpd.conf file. ]

If you check the “30-day trial” or “Developer Edition” checkbox, you don’t have to enter a Serial Number. The 30-day trial is the full Enterprise Edition for 30 days, and then it turns into the Developer Edition. So there’s no good reason not to check the 30-day trial and get 30 free days of serving pages to an unlimited number of IP addresses. Go ahead, don’t worry, Macromedia won’t mind. They want to show you what it can do.

I recommend the “Multiserver configuration”, with the JRun 4 J2EE server. Here’s why: This last summer, I was so impatient to try ColdFusion on the Mac, I tried to install the Tomcat J2EE server and run the (generic J2EE) cfusion.war file on top of Tomcat. Even though I’m a professional ColdFusion developer, I couldn’t get it to run, probably because my Tomcat’s version of J2EE was incompatible (according to CFMX internalist and Mac user Sean Corfield). So my advice is, unless you’re a J2EE expert, just install the JRun that comes with the 7.01 installer. It’s guaranteed to be a compatible J2EE version, and the installer does everything for you, including connecting JRun up to the Apache server, establishing the context root and registering to handle files with ColdFusion suffixes. And it’s so much easier on the nerves than installing Tomcat.

When the installer prompts you for the ColdFusion Administrator password, it’s asking you to make up a password, so that only you can get into the administration screens. You’re installing a server. That makes you the server administrator. By entering an unguessable password, you’re protecting your CF Server against unauthorized configuration changes.

It’ll also ask you if you want to turn on Remote Development Services (RDS). My advice is, unless you know what RDS is and have a good reason to use it, do not turn on RDS. It allows any Dreamweaver user who knows the RDS password (and can see your machine on the network) to access your whole machine. That’s not a bug, by the way. That’s what it’s intended to do in a trusted, cooperative environment. But clearly, it’s a major security hole that you don’t want to open up unless you know what you’re doing and have very good reasons to do so.

Once it’s installed, you will be prompted to restart your machine. This ensures that the J2EE, ColdFusion and Web servers will start up in the proper order, and CF will be usable.

Initial Configuration

After restarting, using any browser, go to http://localhost/CFIDE/administrator/index.cfm and bookmark it. That’s the URL of your ColdFusion Administrator pages (CF Admin). Reenter the password you gave it during the installation process.

The first thing you have to define in CF Admin is where your CF pages will reside. You do this by going to “Mappings.” Use the left side navigation bar, which has the familiar Finder metaphor of a list with disclosure triangles to show and hide major groups. You can see “Mappings” at the bottom of this graphic:

Mappings

Your CF pages could reside anywhere on your hard drive, but let’s assume you want your document root for Web pages to also be your document root for CFML pages. Enter / as the Logical Path, indicating “any CF relative URL that begins with /”. Then enter /Library/WebServer/Documents as the Directory Path, indicating Apache’s (default) document root. (As always on Unix, paths are case-sensitive.) When you’re done, press the Add Mapping button. This will cause what you just entered to appear in the Active ColdFusion Mappings, as shown at the bottom of this graphic:

Mappings 2

In actuality, Logical Path and Directory Path will get cleared when you press Add Mapping. But I reentered them on the screen before taking this snapshot, so that it would function as both a “before” and “after” snapshot.

I also recommend that, under Debugging & Logging > Debugging Settings, you should turn on Enable Robust Exception Information and turn off Enable Debugging. The reason: Enable Debugging is reputed to have a “memory leak.” It’s unclear whether the memory leak occurs only on Windows but, generally speaking, you’ll probably want to turn Enable Debugging off unless you need it:

Debug settings

Stuff You Can Do With CF

First and foremost, you can install Oracle or Sybase (muscular, commercial database servers), MySQL (a well-known and popular open source database server) and/or other database servers. You can define databases on those database servers and fill them up with data. You can define “datasources” in ColdFusion Administrator to access those databases. And then you can create CF pages to maintain and search those databases.

Database maintenance and searching is about 90% of dynamic Web page development in the real world. That’s what Google, Yahoo and all the other Web page search engines do. They search databases of other Web pages’ contents and generate a dynamic listing of the search results. For that matter, that’s what Match.com, Yahoo Personals and LavaLife do too, except that they search databases for people, not Web pages. Amazon and eBay do the same things with products for sale. Credit card purchases, too, are actually database updates.

If you’re going to play around and teach yourself CF, start with a simple personal database that you know and understand thoroughly, such as your music collection, book library or even the names, addresses, phone numbers and birthdays of the people you know. Assuming you choose to define a database for your books, you could use CF to search for an author or title, or to display your books alphabetically, by topic or by where they are on your bookshelves.

Personal projects are a fun way to start, and even after you’ve been doing Web development for ten years, as I have, you’ll never run out of new ways to use your programming skills to support your hobbies.

Sudoku puzzle solver

A sudoku puzzle solver.

I’m a 4th degree black belt in judo. I’m currently setting up a CF site to maintain our black belt association’s membership roster, dues, ranks, time-in-rank, officers, requests for tournament scheduling dates, current tournament schedules … anything we ever wanted to track. It’s pretty sketchy right now, as you might expect. (After all, I installed CF Server just a couple of weekends ago.) But before long, we’ll be able to access, maintain and search this information from anywhere on the Internet.

There are other, non-database things you can do with CF, of course. You can write an “anonymizer” to accept Web requests, use <cfhttp> so that your server can act as a browser, and repackage the Web pages you retrieve as if they came from your server. A typical use of an anonymizer is to mask the IP address of the actual requester, hence the name.

Another non-database thing you could do is define a “directory watcher” using CF’s Event Gateway. When a new file is copied to a “drop box” folder, that event can trigger a CF page to execute. That page might move the file to a different directory, according to its name or other characteristics, for example. Or, in a business environment, your customers might FTP the files into the directory, and you might generate reports from the files’ contents.

Or you can define an AIM Screen Name (in AIM or AOL) and use the Event Gateway to have a CF page respond to IMs sent to that Screen Name. Then, at work, you can instant message “schedule for today” to that Screen Name, which you’ve programmed to respond with all the events you’ve scheduled for later in the day. That would be a combination of non-database (IM) and database (looking up your schedule). Or you might do the same thing with SMS (cell phone) text messaging, so that you don’t have to be at a computer with AIM installed.

It’s really amazing what ColdFusion can do, once you learn it. It’s not limited to the Web anymore. In fact, because it’s a lot more flexible than Automator, you could even use it to do miscellaneous automated tasks on your Mac.

Learning ColdFusion

The ColdFusion installer also installs a complete reference library on CFML at http://localhost/cfdocs/dochome.htm that you can read whenever you get stuck on how to do something. There are plenty of two-inch-thick books on the market. Ben Forta is a pretty famous CF author, and there are others. You can also take courses from Macromedia or one of their partners, such as Fig Leaf Software in Washington, DC. And you can attend the Washington Area Macromedia Organization’s monthly meetings for free; see http://new.wammo.org/ for more details. I’ll be giving a presentation on the Federal E-Authentication Initiative at the December WAMMO meeting.

If you’re already familiar with CF

If you write cross-platform CF code and want to test for what platform you’re currently running on, Server.OS.Name will be “Mac OS X” on a Mac. If you use the built-in function ExpandPath, the result will be in Unix format (“/dir/dir/file”), not traditional Mac format (“vol:dir:dir:file”). That’s the format that <cffile> expects, so it’s not a problem. I haven’t encountered any Mac-implementation problems.

Not much else to say. It just works, largely as it would on any other Unix platform.

In conclusion

It’s nice to play around with it, but you won’t know the real power of ColdFusion till you use it in the workplace. ColdFusion is primarily for professional Web developers who have to code a lot of dynamic pages and need a Rapid Application Development environment to help get the big jobs done.

I once bragged in a conference call that I could define a desperately needed new Web Service in only ten minutes using CFMX. After the call, one of my managers cornered me in the hallway and asked, “Seriously, Steve, how long is it really going to take?” I looked him straight in the eye and said, flatly, “ten minutes.” A half-hour later, I got an e-mail to go ahead and ten minutes later, I sent back the reply: “Done.” If you know what the term “Web Service” means, and if you’ve ever taken days or weeks writing one (client or server) in Java, you know how jaw-droppingly fast ten minutes is to create a Web Service.

Once you know the tags and functions, ColdFusion makes it trivially easy to do lots of things, almost as fast as you can type: E-mail (SMTP and POP), FTP, LDAP, SQL database access, dynamic generation of charts, graphs, PDF files and Flash components, SMS text messaging, Verity full text search, Web Services, client-side data validation, file and directory I/O, regular expression find and replace, XML parsing, … the list goes on and on. And, if you’re feeling constrained by what you don’t know how to do yet in CFML, you can even manipulate Java objects directly from within CFML. In other words, ColdFusion can also do anything that Java can do.

That’s why Mac ColdFusion developers have been clamoring for so long for Macromedia to support ColdFusion on the Mac. And that’s why the 7.01 release is such a major cause for developer celebration. “Merrimack,” indeed.

(There is also a companion PDF file with detailed CFMX installation instructions.)

About the author

Steve Seaquist is a Certified Advanced ColdFusion MX Developer and a Mac user since the 128K Mac. He works as a contractor at the US Small Business Administration.