Configure, compile, and start
All Apache products that I've worked with include steps for configuring, compiling, and starting the product. This process gets the code ready, tells the software how and where to install, and so on.
To configure the Tomcat software, type:
cd $CATALINA_HOME/bin ./configure --with-java=/usr/java
export JAVA_HOME ./configure
With the Tomcat software configured, it's time to compile it.
Listing 5 shows the code for building the Tomcat binaries and libraries.
Listing 5. Build the binaries and libraries
# gunzip jsvc.tar.gz # pwd /opt/apache-tomcat-6.0.16/bin # tar -xvf jsvc.tar # gmake
Make sure that the path to
gmake is in your
PATHS (for example, ./sfw/bin/).
Note: The Tomcat site states that you should use the GNU
instead of the native BSD
make command on
The code in Listing 6 generates the executable file, .jsvc. This file is required to successfully run Tomcat as a daemon.
Listing 6. Set the permissions on jsvc and copy
chmod 775 jsvc cp jsvc .. cd ..
You can start the server from the CLI or from a Java program as an embedded server. Furthermore, the server can run as a daemon, which will run automatically, similar to a service setup in a Windows environment.
Listing 7 shows the basic startup script for Tomcat.
Listing 7. Run the basic startup script
cd $CATALINA_HOME/bin ./startup.sh cd ../logs
Check catalina.out for errors! If you use
less on this file, type
to go to the bottom of the file. Or, you can type something like:
tail -50 catalina.out
to check the last 50 lines of the file for errors.
Although doing so is beyond the scope of this tutorial, you can also customize the startup process by modifying the Tomcat code or by implementing your own LifecycleListeners.
You can start the daemon using a variety of options, such as
-user for non-root user,
to specify the .pid file location, and
-outfile to specify the error and output
file logs, respectively. For a complete list, find your jsvc process, and type
./jsvc -help. Listing 8
shows an example of a jsvc startup script.
Listing 8. Example jsvc startup script
Bash#./jsvc –home /usr/jdk/instances/jdk1.5.0 \ –Dcatalina.home=/opt/apache-tomcat-6.0.16 \ -cp ./bin/bootstrap.jar -outfile ./logs/catalina.out \ -errfile ./logs/catalina.err \ org.apache.catalina.startup.Bootstrap
It is also very helpful to use the Tomcat.sh script included under the jsvc/bin directory. However, you will need to edit the variables to make sure the paths and such match your environment.
The base Tomcat installation installs an internal HTTP server—Coyote HTTP/1.1—on http port 8080. For this architecture and setup, you don't need a separate Apache HTTP Server. You can change the ports to a more typical Web server port, like 80, simply by editing the server.xml file under the $CATALINA_HOME directory tree. You can also change the default Secure Sockets Layer (SSL) port to a typical SSL port, port 443. The server.xml file is where Tomcat gets most of its core configuration server information.
You can verify whether you started Tomcat successfully by going to http://localhost:8080/. You should see a startup page similar to Figure 3.
Figure 3. Initial Tomcat administrative console welcome page