Skip to content

Installing Apache Tomcat on OS X Yosemite

Michael Hulse edited this page Jul 17, 2019 · 20 revisions

There’s a couple of solutions for local Apache Tomcat development on a Mac.

I prefer, and suggest, option #3 below.

Do this first!

Though, before installation, install and setup Java.

  1. Go here and install Java. This installs the “Web” plugin. Alternatively, download the Java installer from Apple (here’s the one for Yosemite) and you will have access to development tools like javac (for command line compilation).

  2. Add this to your .bash_profile:

    # Oracle version (no javac):
    export JAVA_HOME='/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home'
    # Apple version (includes javac):
    export JAVA_HOME=$(/usr/libexec/java_home)
    # Pick or or other of the above.
    # Check my .bash_profile for real world example:
    # https://github.com/mhulse/dotfizzles
  3. Reload your profile (or, restart computer):

    $ source ~/.bash_profile

The above steps apply to all options listed below.

Option #1: Bitnami’s Tomcat

One advantage to using the Bitnami Tomcat installer is that it comes with:

  • Apache 2.4.10
  • Apache Tomcat 7.0.57
  • MySQL 5.5.40
  • Apache Ant 1.8.1
  • Ant-Contrib 1.0b3
  • PHP 5.4.34
  • PHPMyAdmin 4.2.9.1

Installation instructions:

  1. Download and install the Bitnami “Tomcat 8.0.18-0 Dev (64-bit)” OS X installer (or, get the version that matches the version on the live server).

  2. Once installed, symlink your version-controlled JSP app to the webapps folder of the Tomcat installation. For example, I keep my repos in ~/github/organization-or-team:

    $ ln -s ~/github/organization-or-team/repo/ /Applications/tomcatstack-7.0.57-0/apache-tomcat/webapps/
  3. Next, open tomcatstack-7.0.57-0/manager-osx.app, click on the “Manager Servers” button and start “Apache Web Server” and “Tomcat Server”.

    Alternatively, you can use the command line:

    $ cd /Applications/tomcatstack-7.0.57-0/
    $ ./ctlscript.sh start
    $ ./ctlscript.sh stop
    $ ./ctlscript.sh restart
    # Or, by the service:
    # ./ctlscript.sh (start|stop|restart) apache
    # ./ctlscript.sh (start|stop|restart) mysql
    # ./ctlscript.sh (start|stop|restart) tomcat

Check out the README.txt file at the root of Bitnami’s Tomcat install for more useful information.

Option #2: Homebrew

You can install Tomcat using Homebrew.

I don’t recommend this …

Why? Because once you install Homebrew's version of Tomcat, you have to edit Brew-installed Tomcat files … I don't like the thought of touching Brew's packages directly, so I don't think using Brew to run Tomcat is the best option.

$ brew install tomcat
# Reload your profile:
$ source ~/bash_profile
# Start or stop Tomcat:
$ catalina start
$ catalina stop
# View available commands:
$ catalina -h

Complete installation instructions:

Option #3: Just Tomcat

I consider this to be the best middle-ground option because:

  • It does not come with all of the overhead as the Bitnami installer.
  • It’s easier to edit core files, unlike the Homebrew option.

Installation instructions:

  1. Make sure Java is installed and JAVA_HOME environment variable is available.

  2. Visit http://tomcat.apache.org/.

  3. Click on the latest Tomcat version in the sidebar under Download heading.

  4. Under Core download the zip binary distribution.

  5. Put the extracted folder anywhere on your HDD (I put mine in /Applications).

  6. Create an alias to Tomcat:

    $ ln -s apache-tomcat-8.0.18 tomcat
  7. Make catalina script executable:

    $ chmod a+x /Applications/tomcat/bin/catalina.sh
  8. Add this line to your .bash_profile:

    # http://tomcat.apache.org/
    export CATALINA_HOME='/Applications/tomcat' # Make this an alias.
  9. Add this function to your ~/.bash_functions:

    # Shortcut function to control Apache Tomcat Catalina script:
    catalina() {
      # Long-hand version:
      # Start:
      # $CATALINA_HOME/bin/startup.sh
      # ... or:
      # $CATALINA_HOME/bin/catalina.sh start
      # Stop:
      # $CATALINA_HOME/bin/shutdown.sh
      # ... or:
      # $CATALINA_HOME/bin/catalina.sh stop
      # See .bash_aliases for related alias.
      if [ -z $1 ]; then
        OPTION=start
      else
        OPTION=$1
      fi
      $CATALINA_HOME/bin/catalina.sh OPTION
    }
  10. Add this alias to your ~/.bash_aliases:

    # Apache Tomcat:
    alias tomcat=catalina

    Use the above alias to run any other Tomcat catalina commands.

  11. Reload your profile: $ source ~/.bash_profile.

  12. Symlink your JSP app:

    $ ln -s ~/github/organization-or-team/repo-name/ /Applications/tomcat/webapps/repo-name/

    Tomcat 7.x: If you have any issues with getting symlinked apps to work, navigate to /Applications/apache-tomcat-7.0.78/webapps/ and create a directory named META-INF and create a file, within this directory, named context.xml; copy/paste the following into this file:

    <?xml version="1.0" encoding="UTF-8"?>
    <Context path="/myapp" allowLinking="true">
    </Context>

    Restart Tomcat.

  13. Add this to /Applications/apache-tomcat-7.0.78/conf/tomcat-users.xml, right before the closing </tomcat-users>:

    <role rolename="manager-gui"/>
    <user username="tomcat" password="" roles="admin-gui,manager-gui,manager-script,manager-jmx,manager-status"/>
  14. Start or stop Tomcat:

    # Start:
    $ tomcat
    # ... or (redundant):
    $ tomcat start
    # Stop:
    $ tomcat stop
  15. Visit http://localhost:8080/app-name and your app should load; you may need to include a WEB-INF/ or META-INF/ depending on your JSP/JAVA application needs.

Check the RUNNING.txt file at the root of the Tomcat install for more useful information (like, tailing the `logs/catalina.YYY-MM-DD.log log files if you run into any issues).

:)

Clone this wiki locally