rss
twitter
    @docwisdom huh?

Multiple ColdFusion 9 Instances with JRun and Apache

I was asked recently to assist with setting up multiple ColdFusion 9 instances when using Apache as the web server. When using IIS, its pretty easy to run the 'Web Site Configuration' and tell IIS which CF instance to use for which sites, but with Apache, there is a bit more involved...not a whole lot, in my opinion, but there is more. 

Note: This assumes you already have ColdFusion installed and hooked up to Apache.

First, let's create a new ColdFusion Instance. This is easy enough using the CF Administrator. (Yes, I know there are other ways, like deploying CF as a .war file but using CF Administrator is more user friendly). We create a new CF instance by navigating to the 'Enterprise Manager --> Instance Manager' in CF Administrator (you will only see this menu option in Developer and Enterprise editions of ColdFusion).

On the next page, we want to click 'Add New Instance'.



Simply fill out the form, giving the new server a 'name' (you should be able to leave the default Server Directory) and clicking 'Submit'

Now..we wait...this may take a while - once the new instance is created, it should be started automatically and you should be able to hit the CF Administrator for the new instance by going to http://localhost:{port #}/CFIDE/administrator/ where {port #} is the 'HTTP port' shown in the 'Available Servers' list.

NOTE: If, like me, you use ColdFusion debugging, and have specified a debugging port in jvm.config and have other servers running that are using jvm.config at startup, the new instance will not start - to fix this, start the new instance with a different jvm.config file or shutdown any other instances of ColdFusion that are running)

Here is where we need to take a little detour to get the information needed for Apache. If its not already started, fire up the JRun Administrator and browse to http://localhost:8000. You should be prompted for a login (the username should be 'admin' and the password will be the password you specified for CF Administrator when you first installed ColdFusion).

Once you are logged in to JRun admin, you should see a list of available servers (and your new server should be there).

If your new server is not started, start it. Once it has been started, click on the name of your new server. From here click the 'Services' menu item

On the services page, note the 'Proxy Port' specified. Also, if it is not started (which it likely is not), start the 'ProxyService' by clicking the 'play' button.

We can now close the JRun Admin (and stop the service is you so desire) and open up our Apache file used for specifying virtual hosts (depending on the version of Apache, this may be a separate file form main config).

Create a new <virtualHost> block or use an existing one and inside the <virtualHost> block add the following line:

view plain print about
1JRunConfig Bootstrap 127.0.0.1:{proxy port}


Where {proxy port} is equal to the proxy port we noted in JRun admin for our new instance.

To test that we are using the new instance, lets create a test file in the document root of our virtual host with the following code

view plain print about
1<cfdump var="#server#" />

When we view the page, we can verify the new instance is being used by looking at the 'rooter' key of the 'coldfusion' structure. In my case, it looks like this:

'Scott_test' was the name I gave my CF Instance (by default ColdFusion will create new instances in a directory under 'servers' with the same name as the instance).

I know this may seem complicated, but after you do it a few times, its pretty easy.

CF7, CF8, Jrun and the JVM

As I mentioned in this post, I described, briefly how my development environment is set up, and how I installed ColdFusion 8 onto the same JRun server where I have ColdFusion 7 installed.  A reader inquired about the JVM and if there are any conflicts.  Well, the answer is no, there are not.  Why?  Well, becasue when you deploy ColdFusion 8 as a .ear file onto a server running ColdFusion 7, JRun will use the JRE specifeid in the java.home variable in {jRun root}/bin/jvm.config, which in my case was 1.4.2_09.

Now, I have been running this configuration since the public beta and have not run into any issues with performance, or even errors occurring when running ColdFusion 8 code.  However, I wanted to set-up my ColdFusion 8 to use the same JRE it would if I had done a different install (stand alone, or multi-server).  This was easy enough as you can create custom jvm.config files and use them to run your JRun 'servers'.

Here's to do it.
Disclaimer: This is for Windows only.  I assume the procedure would be similar in a different environment.

  1. Download the latest Java SDK and install it. (You may be able to use the JRE alone, but I didn't test this)
  2. Make a copy of jvm.config (located in {JRun root}/bin } and name it jvm_cf8.config. (You can name it whatever you would like, but the rest of the instructions assume you use this name)
  3. Change the java.home variable from "C:/JRun4/jre" (It may be different for you) to {new SDK Install path}/jre and save the file.
  4. If its running, stop the ColdFusion 8 service.
  5. Open a command window and "cd" to {JRun Root}/bin
  6. Test the new config by typing jrun -config jvm_cf8.config -start {the name of your ColdFusion 8 server in Jrun}.  If you don't get any errors, you can now set up your Windows service to use this config file.
  7. Pressing crtl+c should shut down the JRun server you just started.
  8. Type the following to remove the windows service jrunsvc -remove {the name of your ColdFusion 8 server in JRun}
  9. Now you need to reinstall the Windows service and tell it to use the new config jrunsvc -install {the name of your ColdFusion 8 server in JRun} -config jvm_cf8.config.
  10. You should now be able to start ColdFusion 8 from the Services MMC in Windows.


To verify you are using the updated JVM, log into the ColdFusion Administrator for ColdFusion 8 and go to 'System Information' (It's the blue icon on the top right side of the page) and check the JRE and JVM values.

Running CF8 & CF 7 on JRun with Apache

On my development machine, I run ColdFusion 7 in 'multi-server' mode.  This comes in handy if you need to create a separate instance of ColdFusion because of needs of a project or client.  I also run Apache as my web server.  While I am not a big fan of the httpd.conf file (mostly out of lack of familiarity), it makes it a lot easier to run multiple web sites on Windows XP. (Yes, I know there are tools that allow you to do this with IIS, but all the ones I have tried have been buggy and made messing with httpd.conf a pleasant experience). I also add sites to my HOSTS file and give them a 'domain' of 'dev' (boyzoid.dev, for example).  This makes it easier for me to keep track of which environment I am in, and in a lot of cases, save some typing as I usually abbreviate the project (mic.dev, for example).

Like most ColdFusion developers, I wanted to play with ColdFusion 8 when it went into public beta.  I wanted to be able to use ColdFusion 8 and not have to deviate much from my development practices. I wound up installing ColdFusion 8 as a .ear file and deploying it to the same instance of JRun on which ColdFusion 7 is running.  This way I could manage all my ColdFusion instances in one place.  I ran into one small problem though, how do I get a site configured in Apache to use the ColdFusion 8 server rather than the ColdFusion 7 server? For those who may not know, when you are using IIS and multiserver install of ColdFusion, when you add news 'sites' to IIS, you ccan specify what instance of ColdFusion to use for the site.  The answer was surprisingly simple.

First, keep in mind these instructions pick up AFTER ColdFusion 8 has been installed and deployed to your JRun server and the server is running.  It also assumes that Apache has already been configured to work with ColdFusion

1. Go into your JRun Admin and find the 'server' you specified when you deployed ColdFusion 8, and click the link.  In my case, its named 'cf8'.

2. In the resulting screen, click the 'Services' link in the navigation bar.

3. In the next screen, click the 'Start'button next to the 'Proxy Service'.  Take note of the 'proxy port', we will need that in a bit.

4. Create a directory, with whatever name you woud like) under {Jrun}/lib/wsconfig (In my case, I named it 'cf8'...original, I know)

5. Open up httpd.conf and create a <virtualHost> to use, or you can use an existing one.

6. In httpd.conf and look for a block of code that looks like:

# JRun Settings
LoadModule jrun_module "C:/JRun4/lib/wsconfig/1/mod_jrun20.so"
<IfModule mod_jrun20.c>
    JRunConfig Verbose false
    JRunConfig Apialloc false
    JRunConfig Ssl false
    JRunConfig Ignoresuffixmap false
    JRunConfig Serverstore "C:/JRun4/lib/wsconfig/1/jrunserver.store"
    JRunConfig Bootstrap 127.0.0.1:51020
    #JRunConfig Errorurl <optionally redirect to this URL on errors>
    #JRunConfig ProxyRetryInterval 600
    #JRunConfig ConnectTimeout 15
    #JRunConfig RecvTimeout 300
    #JRunConfig SendTimeout 15
    AddHandler jrun-handler .jsp .jws .cfm .cfml .cfc .cfr .cfswf
</IfModule>


This information is what Apache uses to pass off requests to ColdFusion.

7.  Copy the following lines:

JRunConfig Apialloc false
JRunConfig Serverstore "C:/JRun4/lib/wsconfig/1/jrunserver.store"
JRunConfig Bootstrap 127.0.0.1:51020


8. Paste the above lines inside the <virtualHost> block you created, or chose, in step 6.

9. In the line: JRunConfig Serverstore "C:/JRun4/lib/wsconfig/1/jrunserver.store", change the path so it matches the path of the directory you created in step 4.  Make sure you keep the '/jrunserver.store' on the end.  Don;t worry about the file not being there, it will get added auto-magiaclly.

10. In the line JRunConfig Bootstrap 127.0.0.1:51020, replace the port number (the number after the colon) with the 'proxy port' number we noted in step 3.

11. Restart Apache.

The <virtualHost> you created will now use ColdFusion 8 instead of the default server (which in my case was ColdFusion 7).

How do we know its using ColdFusion 8? Easy, just create a test page with <cfdump var="#server#" />, you'll see a version number that begins with '8'.

You can also use this method for pointing Apache to different instances of the same version of ColdFusion, since, as far as JRun cares, they are all just servers.