I prefer the manual process of installing and upgrading software on a live server as it is less likely to break things and the reversal process is easier as well. So that's the way I choose to go;
To find out which version of Ubuntu you have run the following command:
On my machine the output is:
If you want to find the kernel details run (uname -a).
To find the linux distro you can also run (cat /etc/issue).
To check if Java is installed run:
dpkg --get-selections | grep sun-java
which should output:
running the command (java -version) should give you the following output assuming the "java" executable is on your $PATH variable.
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode)
If you don't have Java installed the easiest way is run this command (sudo apt-get install sun-java6-jdk)
Tomcat 7 Installation
It's recommended to use your web browser to download Tomcat but if you know exactly which version you want and you know the url then wget would suffice.
Calculate the md5 checksum using the command (md5sum apache-tomcat-7.0.2.tar.gz) it should output:
The above is just to make sure your download wasn't corrupted.
Extract Tomcat 7.0.2 Beta
To extract the content of the archive run the following command (tar xvzf apache-tomcat-7.0.2.tar.gz)
Move the tomcat folder to a location which it will sit and serve webapps. I moved it to /usr/local/tomcat, but am not sure what the best place is, maybe someone could let me know?
sudo mv apache-tomcat-7.0.2 /usr/local/tomcat/
Set JAVA_HOME variable
To check if the $JAVA_HOME environment variable has been set or not run the following command (echo $JAVA_HOME) which should output:
Tomcat requires setting the JAVA_HOME variable. You can set it in .bashrc or startup.sh. Again not sure what the best place is.
To place it in your .bashrc file.
Add the following line:
Logout of the shell for the change to take effect.
Startup Tomcat 7.0.2 Beta
Start tomcat by executing "startup.sh" script in the tomcat/bin folder.
Automatic Starting at boot
For a live server you need to make tomcat automatically start at boot up just in case you need to restart the server; Add a start/stop script to init.d script startup directory.
sudo vi /etc/init.d/tomcat
Paste in the following:
# Tomcat auto-start
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid
case $1 in
Make the script executable:
sudo chmod 755 /etc/init.d/tomcat
Link the start/stop script to the startup folders with a symbolic link.
sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
You might also want to put some symbolic links in rc0 and rc6 directories.
Or alternatively let ubuntu create the symbolic links automatically by running this command:
sudo update-rc.d tomcat defaults
update-rc.d: warning: /etc/init.d/tomcat missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
Adding system startup for /etc/init.d/tomcat ...
/etc/rc0.d/K20tomcat -> ../init.d/tomcat
/etc/rc1.d/K20tomcat -> ../init.d/tomcat
/etc/rc6.d/K20tomcat -> ../init.d/tomcat
/etc/rc2.d/S20tomcat -> ../init.d/tomcat
/etc/rc3.d/S20tomcat -> ../init.d/tomcat
/etc/rc4.d/S20tomcat -> ../init.d/tomcat
/etc/rc5.d/S20tomcat -> ../init.d/tomcat
The difference is that it makes sure tomcat start at each run level however in practical terms if runlevel 2 is reached tomcat will start so run level 3,4 and 5 will be ignored as tomcat would already be running from when run level 2 was reached. The nice thing about this automatic install of symbolic links is that it is easy to add/remove them. Also they add the "stop" script at run level 0 and 6 which should be done!