webfaction-tomcat-installer /

Filename Size Date modified Message
9.0 KB
Updated to 7.0.57
4.7 KB
Fixed disabling AJP port

Tomcat install script for WebFaction

What does it do?

This creates an Apache Tomcat server, version 7.0.57, and the front-end web server proxies incoming requests to the Tomcat server listening on an unprivileged port. It also makes some configuration adjustments.

An admin user for the Manager App at the /manager URL path is also added. The username is "admin" and the password is the one specified in the "Extra info" field during the creation process. Please note that any subsequent changes to the admin password will not be reflected in the control panel's "Extra info" field.

The AJP protocol is disabled, since WebFaction is using nginx as the front-end to proxy incoming requests to the Tomcat server and nginx doesn't support it.

The shutdown port Tomcat uses to terminate itself is also disabled. The process is shuting down with a kill signal from the operating system instead.

The main log, ~/webapps/<app_name>/logs/catalina.out, is also moved to your ~/logs/user/<app_name>.log file, with a symbolic link pointing back to it.

You should be able to start the server by executing the ~/webapps/<app_name>/bin/ command. You can stop the server by executing the ~/webapps/<app_name>/bin/ one.

A cron job is created to restart the Tomcat server every 20 minutes if it is not already running.

The official Tomcat documentation is available here.


This is not an official WebFaction one-click installer, so please address any installer issues on the project's issue tracker.

The installer was inspired after the Install Tomcat, howto or step by step tutorial question on WebFaction's Q&A forum.


To install this you need to:

  1. Go to the Add new application form.
  2. In the Name field, enter a name for the application.
  3. In the App category menu, click to select Custom.
  4. In the App type menu, click to select Custom install script.
  5. In the Script url field, enter the URL of the installer file and click the Fetch scipt link.
  6. In the Extra info field, type in your "admin" user password.
  7. Click the blue Add application button.

Now, you can create or modify a website entry which points to your new Tomcat application. Requests to that application’s URL will be proxied by your server to the port number assigned. Your application can then listen and respond to requests on that port.


Regarding the shutdown port

Tomcat listens to a second port by default, which is used by the shutdown script to terminate the process.

Tomcat's ~/webapps/<app_name>/bin/ script, when executed, makes a connection to that port in order to close all web applications and shut down cleanly.

But this behaviour is a potential security issue in a shared hosting enviroment, as any user on the server could make a connection to the default 8005 port, using telnet and send a SHUTDOWN string to stop your server as easily as:

$ telnet localhost 8005
Connected to localhost.
Escape character is '^]'.

You can change both the default port, as well as the shutdown string, but that wouldn't stop someone performing a dictionary based attack against your service.

So the installer disables the shutdown port and relies on operating system signals to termiate the process. Because of that, you will see the following message, when you try to shut the service down:

SEVERE: No shutdown port configured. Shut down server through OS signal. Server not shut down.
Killing Tomcat with the PID: NNNNN

That's perfectly ok, despite the SEVERE status. It just says that the command couldn't connect to the shutdown port and needed to use the kill command to stop the server.

If you do want this feature re-enabled, then assign yourself a port by creating a "Custom app (listening on port)" application from the control panel. Then open your ~/webapps/<app_name>/conf/server.xml file on an editor and search for the first Server tag, the one with the shutdown option, and change the port from -1 to the one you've got assigned. Change for example:

<Server port="-1" shutdown="SHUTDOWN">


<Server port="NNNNN" shutdown="SHUTDOWN">

where NNNNN is the port you got assigned from the control panel. And do not forget to change the default SHUTDOWN string to a random one.

Now go to your ~/webapps/<app_name>/bin/ file and find the line where it only says FORCE=1 and change it to FORCE=0. It should be located around line 416.

Install Oracle's JDK

All WebFaction servers come with OpenJDK pre-installed:

$ which java
$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (rhel-
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

If you want to use Oracle's JDK with your Tomcat instance, here's what you do:

  1. Visit Oracle's Java download page and click to download the latest Java Platform (JDK) version.
  2. On the next page, copy the url of the appropriate product to your clipboard. Select the 'Linux x86 tar.gz' file if you are on a CentOS 5 (32-bit) machine, or the 'Linux x64' file if you are on a CentOS 6 (64-bit) one.
  3. Open an SSH session to your account. See WebFaction's Accesing Your Data if you don't know how.
  4. Create a directory to place Java and traverse to that directory. Enter mkdir ~/opt && cd ~/opt and press Enter.
  5. Download the JDK and decompress it. Enter wget -O - --no-cookies --header "Cookie:" "URL" | tar xz, where URL is the one you've copied, and press Enter.
  6. Create a symbolic link for easier easier reference. Enter ln -s jdk1.7.0_09/ java and press Enter.
  7. Add ~/opt/java/bin to your PATH enviromental variable. Enter echo 'export PATH=$HOME/opt/java/bin/:$PATH >> $HOME/.bashrc and press Enter.
  8. Make your .bashrc changes take effect. Enter source ~/.bashrc and press Enter

You should now be using Oracle's JDK:

$ which java
$ java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

If you want to use Oracle's JDK with your Tomcat instance change the JRE_HOME enviromental variable in your ~/webapps/<app_name>/bin/ from:


or, on 32-bit machines, from:




And restart your Tomcat instance.

Install the APR native library

If you've taken a look at your log file during startup, you might have seen the following info line:

INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-1.6.0-openjdk-

To enable the APR based native library for Tomcat, you first need to follow the instructions above and setup Oracle's JDK in your home directory.

When that's done, you need to do the following to compile the native library:

cd ~/opt
tar xzf ~/webapps/<app_name>/bin/tomcat-native.tar.gz
cd tomcat-native-1.1.24-src/jni/native/
./configure --with-apr=`which apr-1-config` --with-ssl=yes --with-java-home=$HOME/opt/java --prefix=$HOME/webapps/<app_name>
make && make install

Then open your ~/webapps/<app_name>/bin/ file and add the following line:


If you have already added some overrides to your JAVA_OPTS variable, then you can append to that directive. It should look for example like:

JAVA_OPTS="-Xmx64m -Djava.library.path=$CATALINA_HOME/lib"

Starting the instance again, you should see to the logs something like:

INFO: Loaded APR based Apache Tomcat Native library 1.1.24 using APR version 1.4.5.