Assuming all virtual hosts live inside the same parent directory then this directory can be set in the script’s configuration on line 5. Once set, adding a new virtual host is as simple as saving it as something meaningful (in this case ‘addvh.sh’) and calling it with the full domain name of the virtual host passed as a parameter like so:
$ su# ./addvh.sh my.domain.com
One important point: this script relies on Apache’s usage of a separate vhosts file in the /etc/httpd/conf directory. This file can be pulled in and read by the main httpd.conf file by adding the following line to it.
What the script does?
1. creates a new document root folder for the virtual host and places an index.cfm test page inside it.
2. adds the virtual host entry to the httpd.conf file
3. adds the virtual host entry to the server.xml file
4. restarts Apache
5. restarts OpenBD
Once the script has run then if all goes well you should be able to browse to your new virtual host and check the CFML parsing by typing http://<new virtual host domain>/index.cfm
Here’s the script:
#!/bin/bash# Configure the firstname.lastname@example.org'# email address of administratorvhroot='/www'# no trailing slash # Create the new document root folderif["$1" = ""]thenecho"No arguments passed. Usage: addvh <vhostName> where <vhostName> is the full domain"echo"(or subdomain) of the virtual host. E.g test.com, mypoject.test.com"exit# Try to create the new document rootelif!mkdir$vhroot/$1thenecho"ERROR: "$vhroot"/"$1" could not be created."elseecho"Virtual host document root created in "$vhroot"/"$1# Add the virtual host to the vhosts fileif!echo"
thenecho"ERROR: the virtual host could not be added to the Apache vhosts file"elseecho"New virtual host added to the Apache vhosts file"# Update the Tomcat server.xml file with the new virtual hostrs=' <Host name="'$1'" appBase="webapps"\
<Context path="" docBase="'$vhroot'/'$1'/" />\
mv tmp /opt/openbd/tomcat/conf/server.xml
echo'New virtual host added to the Tomcat server.xml file'# restart Apache
service httpd restart
# restart Tomcat/OpenBD/etc/init.d/openbd_ctl restart
# create a demo script for testing the CFML works in the new vhostecho'<cfdump var="#CGI#">'>$vhroot/$1/index.cfm
# show the finished messageecho"Complete! The new virtual host has been created.
To check the CFML functionality browse http://"$1"/index.cfm
Document root is "$vhroot"/"$1fifi
I needed to set up a development platform that could serve different dev projects on separate subdomains with several of them using openBD to handle .CFM templates. My chosen platform is Centos 5.5 using the Apache 2.2 web server.
I first tried doing this over a year ago and spent quite a while reading through the various documentation provided by the openBD community but never managed to get it to work. Recently my hosting company (Vivio Technologies) changed their pricing and suggested that I switch from BlueDragon Server JX to OpenBD so I decided to have another go setting up my dev platform so I can test the CFML apps I have running there with openBD before making the switch on the production server.
Since my last attempt the installation process has been made a lot easier due to the OpenBD installer packages created by Jordan Michaels.
I started by installing a fresh VM with Centos 5.5, configuring a couple of subdomains as virtual hosts and creating their respective document root folders under /www. Then, by just running the installer (openbd-1.3-pl0-linux-installer.bin) and accepting all of the default options, I was able to get openBD to successfully serve its demo pages which are contained in the Tomcat webapps/ROOT folder by browsing <CentosVM IP address>/demo/cfdump.cfm.
I also got the openBD administrator by browsing <CentosVM IP address>:8888/bluedragon/administrator/index.cfm
The next stage, getting virtual hosts was not quite so straightforward. There are some really good instructions on the OpenBD Wiki. The salient point here is that the server.xml file in the tomcat’s conf folder needs to have entries made for each virtual host in much the same way as the httpd.conf file does. But on my first attempt at doing this, something went wrong and I kept getting ‘Service Temporarily Unavailable’ errors from the browser when trying to browse a CFM page from a virtual host. I ended up rolling back my VM to a previous snapshot and reinstalling openBD. This time I re-added the virtual host to the server.xml file and it worked. Now, finally after over a year of trying I have a working dev server that uses OpenBD to parse CFM files and I can get on with the next steps….testing my CFML apps and then deploying them to an OpenBD production server and in the process save myself $10 a month for the BlueDragon Server JX license fee.
Update: I wrote this shell script that automates the addition of new virtual hosts
I’ve just spent the last two days preparing a new development environment on a Virtual PC 2007 VM for the application I’m currently building.
The idea behind this setup is that it mirrors as closely as possible the production environment which is CFMX7.0.2 / Centos 5.2 / Apache 2.2.
It took a lot of abortive attempts to get this right but I finally managed it with the help of the very well written walkthrough by Bill Mitchell which itself refers greatly to another blog post by Steve Erat. Mr Mitchell’s guide is great – it covers several different methods of installing the Apache connector in CFMX7 – he can take all of the credit for this, in fact I copied large sections of his procedure (thanks Mr Mitchell :)).
So I’m going to now give a set of precise instructions on how to set up and configure this dev environment that should work first time. I’m also going to be a bit naughty and provide the wsconfig file for download off my server – this will save some more time.
Begin by installing Centos 5.2 on a virtual machine running in Virtual PC – make sure to use “text mode” for the installation as VPC doesn’t support 24bit graphics and will not display the installer properly.
Once installed, open the ports you need in the Centos firewall
Install LAMP (Apache, PHP & MySQL) using Yum (see this article for details).
Reboot the server and check that everything works properly so far. Once you’re sure it is then it is a good time to enable undo disks in VPC as the next phase of the install can go wrong and if it does you can just revert back to this safe position and try again. To enable undo disks:
shut down the virtual machine
in the VPC console open the VM’s settings
select undo disks (6th item) and enable it
restart the VM
Download the coldfusion-702-lin.bin installer from the Adobe download site – on the main Coldfusion download page you will need to click the "related downloads" link to find the correct download
Use the following string replace command on the binary to comment out a line that causes problems
[root@machine]# cat coldfusion-702-lin.bin.backup | sed "s/export LD_ASSUME/#xport LD_ASSUME/" > coldfusion-702-linux.bin
Make the modified binary executable
[root@machine]# chmod 755 coldfusion-702-lin.bin
Execute the installer and select the “Built-In Webserver” option (don’t worry this will be replace with Apache later) IMPORTANT – DON’T LAUNCH THE COLDFUISON SERVER YET – if you do then you’ll have to start all over again.
Open the /opt/coldfusionmx7/runtime/servers/coldfusion/SERVER-INF/jrun.xml file and
Find the entry labeled ProxyService
Add <attribute name=”deactivated”>false</attribute> (changed from true)
Find the entry labeled WebService
Add <attribute name="deactivated">true</attribute> (changed from false)
Find the entry cacheRealPath
Add <attribute name="cacheRealPath">true</attribute> (changed from false)
Save the file
In /opt/coldfusionmx7/runtime/lib/ create a directory called ‘wsconfig’
In /opt/coldfusionmx7/runtime/lib/wsconfig create a driectory called ’1′ (one)
In /opt/coldfusionmx7/runtime/lib/wsconfig create a file called wsconfig.properties and populate it with:
#JRun Web Server Configuration File
# edited by bill 10.31 Thur May 24
and save the file
In /opt/coldfusionmx7/runtime/lib/wsconfig/1 create a file called jrunserver.store and populate it with:
proxyservers=127.0.0.1:51011 The 51011 is for ColdFusion MX 7:
Download this file and place it into the /opt/coldfusionmx7/runtime/lib/wsconfig/1 directory
Change ownership of the wsconfig directory and its contents to the coldfusion user:
Create a symlink to the CFIDE folder in the document root:
ln -s /opt/coldfusionmx7/wwwroot/CFIDE
Restart the apache server
[root@machine ~]# service httpd restart
Start the Coldfusion server
[root@machine ~]# service coldfusionmx7 start
Test everything works properly by putting an index.cfm containing some CFML scripting (eg <cfdump var=”#CGI#”>) into the apache web root and type:
You should see the CGI dump. Then test the coldfusion administrator works
where centos-VM is either a domain that you’ve set up for your new VM or its IP address on your LAN
Now you should have a fully working virtual Centos server with CFML (& PHP) support. Don’t forget to install the MySQL connector J Driver too – I already blogged that one here
Finally you really should should close the VM saving the changes. Before re-launching the VM I would recommend that you copy the VM folder to an archive location – you never know when you might need a freshly installed VM with this environment in the future. Leaving undo disks enabled in Virtual PC is a good idea if you can afford the extra disk space required – if you do break your dev environment in the future and can’t fix it but don’t want to restore the initial image then leaving undo disks enabled will allow you to roll back to the last time you saved your changes. Just remember to save your changes regularly.