How to install Apache Tomcat on Amazon EC2 instance without using a RPM.
Some readers have sent questions asking how to install Apache Tomcat without using a RPM. In this post, we go through quick steps to install Apache Tomcat on Amazon EC2 Instance. You should be done with the installation within 60 seconds of starting. Refer to the original post of Installing Java and Apache Tomcat on CentOS 6.5 on Amazon EC2 with RPM.
Requirements
- Amazon EC2 instance (assumed available)
- Java (assumed installed)
First we download Apache Tomcat binary. We are going to be using Apache Tomcat 7 for this installation.
1 2 3 | $ wget http://mirror.catn.com/pub/apache/tomcat/tomcat-7/v7.0.57/bin/apache-tomcat-7.0.57.tar.gz |
Then explode the tar file
1 2 3 | $ tar zxpvf apache-tomcat-7.0.57.tar.gz |
Now make the following directory for tomcat installation. You could also create a /usr/tomcat/latest and link to another folder. This way you upgrades can be managed easily. This is only a personal preference
1 2 3 | $ mv apache-tomcat-7.0.57 /usr/share/tomcat7 |
Make sure that tomcat user owns the tomcat installation directory
1 2 3 | $ chown tomcat.tomcat tomcat7/* |
Like Java, Tomcat requires an environment variable of its own to be set for it to run properly. Setup the variables in /etc/profile file
1 2 3 4 | CATALINA_HOME="/usr/share/tomcat7" export CATALINA_HOME |
If you would like to run tomcat automatically on restarts or as a service (to control start and stop behaviour) you can do the following.
1 2 3 4 5 | $ touch /etc/init.d/tomcat7 $ ln -s /usr/share/tomcat7/bin/catalina.sh tomcat7 $ chmod 755 /etc/init.d/tomcat7 |
Personally, I also like to tail the logs after tomcat has been started. You can also put the following commands in a handy bash script to make it shorter to invoke them.
1 2 3 4 | $ service tomcat7 stop && tail -f /usr/share/tomcat7/logs/catalina.out $ service tomcat7 start && tail -f /usr/share/tomcat7/logs/catalina.out |
That’s it, you are done. Enjoy your newly installed Apache Tomcat.