The instructions written here are based somewhat loosely on other blog articles I found here and here. At time of writing the Java JDK is at release 6 Update 16, and Tomcat is at version 6.0.20.
There don’t seem to be many hosts out there that support Java Web application hosting. Besides, I really like MediaTemple – their pricing is dead-on, their support is top-notch, and their attention to aesthetics puts them head-and-shoulders above every other Web host I’ve ever used.
But they don’t support Java. That is to say, their “(dv)” service line does not have Java installed by default. The Tomcat button in their Plesk control panel is nothing but a tease!
Fortunately, with full root access, we can add Tomcat to any old (dv).
Step 1: Enable root access
Start this process by enabling root access through your Account Center control panel – this is just easier than using sudo. (If you don’t know what sudo is, this article is probably not for you.)

Step 2: Download Java
First, download the latest Java JDK RPM bin file to your local computer. You can find this download on the Java developers Web site. All we need here is the JDK – no Netbeans, no Java EE. Make sure to download the file ending in .bin, otherwise you’ll have to use a package manager to install it (and I don’t know how to do that).
Since I’ll be using this Tomcat instance exclusively for one of my sites, I install Tomcat there. You can install Tomcat anywhere you want, so long as you remember where you parked the Web server.
I like to keep my applications and their dependencies in close quarters, so I’m going to put my Java installation at /var/www/vhosts/collegeman.net/subdomains/myapplication/dependencies. Upload your .bin file here with any old FTP program.
Step 3: Run the Java installation
Use an SSH client (I like Putty on Windows, and the native SSH client on the Mac) to jump onto your (dv). Switch to the dependencies path you created, and the change the permissions on the .bin file with the following command
Now you can run the Java installation by typing the following command
You’ll have to hold down the enter key for a while to scroll through the Java license agreement. At the end you’ll be asked to agree to the terms: type ‘yes’ and press enter. Assuming the installation completes successfully, you can move onto the next step. (If it doesn’t complete successfully, contact @kennethreitz.)
Step 4: Download Tomcat
You can find the latest Tomcat release on the Tomcat Web site. Download the zipped tar-ball (.tgz or .tar.gz), and make sure you’re downloading the Core, not the Deployer or the Source. (If you happen to need the Deployer, I have no experience with this version of Tomcat – sorry.)
This file you should be able to download directly to your (dv) with the following command
wget http://apache.inetbridge.net/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.tar.gzcopy code
Make sure that when you run this command, you’re in the folder into which you’d like the download saved.
Step 5: Unpack Tomcat
Once the file is on your (dv), unpack the zip file with the following two commands
gunzip apache-tomcat-6.0.20.tar.gz tar -xf apache-tomcat-6.0.20.tarcopy code
This should create an folder named apache-tomcat-6.0.20. I prefer to have Tomcat live in a folder simply named tomcat, and I prefer to have this folder be a sibling to the httpdocs folder in my application root. So I move the tomcat folder there with the following command
mv apache-tomcat-6.0.20.tar /var/www/vhosts/collegeman.net/subdomains/myapplication/tomcatcopy code
Step 6: Test Tomcat
Using my path for the example, run the following command
./var/www/vhosts/collegeman.net/subdomains/myapplication/tomcat/bin/startup.shcopy code
Tomcat will report four pieces of information, boiling down to the location in which Tomcat is installed and the location in which Java is installed. You will then be returned to the command prompt. If you don’t see any other output from this command, you can assume Tomcat is running. Test access to Tomcat with the following URL
http://yourdomain.com:8080
If what you see is the Tomcat Management interface, then Tomcat has been installed successfully.
Step 7: Create a Tomcat service
Using the command-line editor vim, create and open a new service file with the following command
vim /etc/init.d/tomcatcopy code
Use the following content to define the service file. Please note where you must configure this file to run on your personal (dv). Once in the editor, press the i key which will put the editor into insert mode. Then paste the configuration below into the editor
# This is the init script for starting up the # Jakarta Tomcat server # # chkconfig: 345 91 10 # description: Starts and stops the Tomcat daemon. # # Source function library. . /etc/rc.d/init.d/functions # Get config. . /etc/sysconfig/network # Check that networking is up. [ "${NETWORKING}" = "no" ] && exit 0 tomcat=/your/path/to/tomcat startup=$tomcat/bin/startup.sh shutdown=$tomcat/bin/shutdown.sh export JRE_HOME=/usr start(){ echo -n $"Starting Tomcat service: " #daemon -c $startup RETVAL=$? echo } stop(){ action $"Stopping Tomcat service: " $shutdown RETVAL=$? echo } restart(){ stop start } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) # This doesn't work ;) status tomcat ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 1 esac exit 0copy code
Save the file by pressing the esc key, entering wq, and the pressing enter.
Next change the permissions on your script to make the file executable
Test the script by executing the following commands
./tomcat stop ./tomcat startcopy code
You may get an error when you run the stop command – this is normal. As long as you can get one full succession (starting then stopping) without errors, then you’re fine.
Step 8 (Optional): Front Tomcat with Apache
There are many things that you do not want Tomcat to be serving, namely static binary (like images) and text files (like CSS and scripts). Honestly, I think this wisdom harks back to older, more inefficient times Tomcat land, still it is the best practice. Doing so does have the additional benefit of being able to use more than one language on a single domain, e.g., PHP + Java. So it’s not all bad.
As I’m pretty sure this task requires some source code compilation, I’m going to document it in a later post.
So do me a favor and let me know if this was useful to you. Was it written well? Did I skip any steps? And most important, were you able to get it to work?
