Install Tomcat in OS X 10.8 Mountain Lion

In this blog post will show us about step installing Apache Tomcat on OS X Mountain Lion. I assume we already have Java installed on our machine. The first step is downloading Tomcat binary distribution in Tomcat website. In this case I use version 7.0.30.

Extract the downloaded binary distribution onto ~/Download/apache-tomcat-7.0.30. Create directory in /usr/local if we don’t have it yet.

sudo mkdir /usr/local

Move ~/Download/apache-tomcat-7.0.30 to /usr/local

sudo mv ~/Downloads/apache-tomcat-7.0.30 /usr/local

To make it easy to replace this release with future releases, we are going to create a symbolic link that we are going to use when referring to Tomcat. Then we also will change owner and make script executable

sudo ln -s /usr/local/apache-tomcat-7.0.30/ /Library/Tomcat
sudo chown -R neutrocode /Library/Tomcat
sudo chmod +x /Library/Tomcat/bin/*.sh

The next step is creating user for tomcat admin by editing tomcat-user.xml

vi /Library/Tomcat/conf/tomcat-users.xml
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>

<user username="admin" password="password" roles="admin-gui,admin-script" />
<user username="manager" password="password" roles="manager-gui,manager-script,manager-jmx,manager-status" />

Add the following text in current user profile .bash_profile

# .bash_profile
export CATALINA_HOME=/Library/Tomcat
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home

export PATH=$JAVA_HOME:$PATH

Start the server with the following command :

# start tomcat
$CATALINA_HOME/bin/catalina.sh start

or

# start tomcat
$CATALINA_HOME/bin/startup.sh

Stop the server with the following command :

# stop tomcat
$CATALINA_HOME/bin/catalina.sh stop

or

# stop tomcat
$CATALINA_HOME/bin/shutdown.sh