Install and Configure A Development Web Server in UNIX PDF
Install and Configure A Development Web Server in UNIX PDF
UNIX
Build a fast, functional, and free Web server while jump-starting
your UNIX skills
15 Jul 2008
Regardless of your motivation, if you're reading this tutorial, you're likely familiar with
the basics of how a Web site works and what may be needed as the lowest common
denominator for accessing an application from your browser (domain, code, Web
browser, database, and so on). As long as you know the basics, have a need for a
Web or application server, have access to a UNIX server, and have a desire to learn
a thing or three about Web server administration, this tutorial is for you.
Objectives
In this tutorial, you will find:
Prerequisites
This tutorial assumes that you have already installed the base UNIX operating
system of your choice. To run the examples in this tutorial, you must also have
Tomcat version 6 installed and running.
System requirements
Your server should have at least 10GB of available hard disk space and a minimum
of 512MB of RAM. You need the following additional tools installed on your UNIX
server before you can begin:
cd /usr
Find . –name *.tar (repeat for *make, *zip, etc.)
• Tomcat code: You need to download the Tomcat version 6 code from the
Apache download site before proceeding. Save the tar.gz file to your
server.
Why Tomcat?
Why should you use Tomcat instead of one of the alternatives, such as JBoss,
Geronimo, or WebSphere Application Server Express?
Tomcat version 6 by itself is a lightweight solution. It does not come with all the Java
Platform, Enterprise Edition (Java EE) features and additional packages found in
JBoss, Geronimo, and IBM WebSphere® Application Server Express, but it also
doesn't require much memory and runs fast even on smaller servers. Plus, it is
available at no cost.
If you're looking to use your new server in an enterprise environment, the more
obvious UNIX flavors are AIX and Solaris. In fact, Solaris has the highest percentage
of enterprise market share. Other UNIX choices include FreeBSD and Mac OS X.
That said, if you decide to use Windows, there are a few differences in Tomcat setup
between UNIX and Windows that you should note before moving on:
Tomcat versions
With numerous fixes included in every release, tweaks, new features, or new ways
perform old tasks, it's sometimes difficult to decide which software version to go with.
In Tomcat, you're faced with the same problem. I recommend looking at the details
in Table 1 to match up your administrative server to the J2EE specification for which
the application you're deploying was coded.
Limitations
Does your Tomcat installation need to be a single server in a development
environment only? Isn't that quite limiting? Yes, it is, as a matter of fact! Tomcat has
actually been downloaded millions of times, and it successfully runs many
well-known Web sites in production environments. However, it has its limitations.
Enterprise environment
The enterprise architecture shown in Figure 1 is a more or less accurate description
of what you may see behind the scenes when you press Enter in your browser. The
architecture consists of recurring elements that I have seen working for clients
around the nation, including multi-million dollar mission-critical applications at IBM
and the United States Air Force. The sections that follow expand on each area in
Figure 1.
Typically, there are guards to your network—routers or firewalls, then proxy servers
(reverse proxy, to be specific) that match up the Web request with the appropriate
domain. There may be a level of authentication and even authorization at the
front-end IBM Tivoli® Access Manager (TAM)/TAM WebSEAL server level before
the request even hits the first server in your network, which will likely be protected by
a demilitarized zone (DMZ).
B. Web servers
Next are the Web servers. Note that all these servers likely have vertical and
horizontal failover, meaning separate hardware at each level that is cloned and
possibly even duplicated at the software level. When your Web server passes the
Web request and does its job of serving up the static content, you may have another
layer of network dispatchers (NDs) or at the very least, a plug-in (such as the IBM
HTTP Server [IHS] plug-in) that performs additional routing.
Now you have a J2EE engine (WebSphere Application Server), which is likely
composed of a Web or servlet container as well as an Enterprise JavaBean (EJB)
container to handle basic and advanced Java functions and business logic. You
likely have multiple adapters to do a myriad of things, including connecting Web
services and IBM WebSphere MQ messages. And more often than not, you have a
database connection pool that connects to a MySQL, IBM DB2®, or Oracle back
end.
When you tie in the potential connections to Lightweight Directory Access Protocol
(LDAP) servers and even legacy servers, you have a true n-tier architecture. Now,
take a look at a starter Web server environment.
Development environment
Look at Figure 2 with the assumption that it's based on a single-server installation on
a single UNIX operating system that also has some means of accessing the Internet
through a browser. This server will house your Tomcat installation, various operating
system-level tools, as well as (possibly) your own local database or, at the least,
software and application code stored in a local repository (local directory structure).
Note: When I say Tomcat server, I'm talking about the whole container.
Although this looks nothing like a true enterprise architecture, you will at least be
able to replicate basic application functionality from your server. You are very
limited, but for all intents and purposes, you're treating this installation as an
example test development server or just a sandbox server to play in if you are an
administrator.
You can choose to set up and run a separate Apache HTTP Server front end with
your Tomcat installation, but this is not recommended for purposes of this tutorial,
because it requires more overhead and a lot more administration and setup. You
would also need the mod_jk module, you'd have to set up proper routing, and so on.
Either way, let's move on to some common questions before proceeding to the
installation and configuration.
JAVA_HOME
First, you must install the JRE according to the instructions included with the
release. I typically choose to use the full Java software development kit (JDK) rather
than just the JRE. If you do, too, set your JAVA_HOME environment variable to the
path name of the directory into which you installed the JDK (for example,
/usr/local/java/j2sdk5.0). Use the following code to set your JAVA_HOME variable:
bash-3.00# export
JAVA_HOME=/usr/jdk/instances/jdk1.5.0
CATALINA_HOME is used to refer to the full path name of the release directory. Use
the following code to set this variable on your server:
This code pertains specifically to the Tomcat version you have installed. When in
doubt, name it after the .tar file you extract, because that carries with it the correct
version in the name.
You probably noticed that I have a few references to Bash in the command samples.
Without getting into boring details, users logged in to UNIX run out of shells on the
server to execute a CLI that allows them to navigate and administer the server. This
is not unlike other operating systems but is more flexible in that you can define that
shell by typing something like Bourne shell (sh) or Bourne-again shell (bash).
In addition, depending on which shell you're using, you can edit the custom shell
profile for your CLI to automatically set PATH variables and even alias characters to
represent useful common commands on the server. To do this, edit .bashrc, .profile
(the default under the bash shell), and so on. Use the vi editor to create this file, then
edit it appropriately under your root, personal, or Tomcat-specific user ID to ensure
that the PATH variables will be set each time you log in to the server.
Under your home directory, create the .profile file (shown in Listing 1), if it does not
exist already, using the standard UNIX editor, vi.
cd ~/ (home dir)
vi .profile
Type i (for insert), and then add each path you set above. An example may look
something like this:
# /bin/sh
stty istrip
PATH=$PATH:/usr/bin:/usr/local/bin:/usr/ucb:/etc
export PATH
umask 077
export SHELL=/usr/bin/ksh
export ENV=$HOME/.kshrc
export EDITOR=vi
export FCEDIT=vi
#Tomcat specific PATHs
export JAVA_HOME=/usr/jdk/instances/jdk1.5.0
export CATALINA_HOME=/opt/apache-tomcat-6.0.16
This may also be a good time to add additional PATH variables to cover all the areas
in which you have tools installed that you're going to reference. For my setup, I also
need to create the following two paths:
Discover the various methods for extracting the server installation file.
mv *tar.gz /opt
Set permissions
Permissions are the lifeblood of a UNIX system. Without the proper permissions, you
can't do anything; without restricting permissions to certain things, any user can do
anything. That is why you first must grant yourself higher-level permissions on the
installation file so that you (or another user) can properly execute it. Next, use the
umask command, shown in Listing 4, to make sure that you can write the files to all
the temp and installation directories appropriately when you extract the installation
code.
cd /opt
chmod +x *gz (same as chmod 775)
umask 007 (makes any new files your user creates to be created with a 770 permission.
Think chmod in reverse)
gunzip *.gz
This command extracts your application files. Type ls -latr to view the extracted
files. If for some reason your installation came with a .bat or .exe file, you can
remove those by typing:
rm *.exe
rm *.bat
When the Tomcat directory established, you can move on to configuring, compiling,
and starting the server.
cd $CATALINA_HOME/bin
./configure --with-java=/usr/java
or:
export JAVA_HOME
./configure
Listing 5 shows the code for building the Tomcat 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 make (gmake) instead of
the native BSD make command on FreeBSD systems.
The code in Listing 6 generates the executable file, .jsvc. This file is required to
successfully run Tomcat as a daemon.
cd $CATALINA_HOME/bin
./startup.sh
cd ../logs
Check catalina.out for errors! If you use cat, vi, more, or less on this file, type
shift G to go to the bottom of the file. Or, you can type something like:
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, -pid to specify the .pid file location, and -errfile 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.
What's a daemon?
A daemon is a non-interactive server application that the operating
system controls by a set of specified signals. Think services in
Windows. This provides for a graceful shutdown of server
applications; the operating system can notify a server application of
its imminent shutdown, and the application has the ability to perform
certain tasks before its process of execution is destroyed.
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.
vi tomcat-users.xml
Add these two lines below in between the two
<tomcat-users> tags
<tomcat-users>
<role rolename="manager"/>
<user username="tomcat1" password="test1234"
roles="manager"/>
</tomcat-users>
Just in case you're wondering, the above user and password are completely
arbitrary. You do not need to create that user with the password on your UNIX
server and can set these to whatever you wish. You will, however, use that
information to log in to the management console.
For additional security, limit the access to that tomcat-users.xml file to only the
owner of the file. To do so, you must set the permissions at 700 or below—for
example:
cd $CATALINA_HOME/bin
./shutdown.sh
./startup.sh ;tail -f ../logs/catalina.out
You should see something similar to this when you tail your catalina.out log file:
Tomcat also has a status application, which displays the status of the Tomcat
server, including memory utilization of the JVM and the number of threads. You can
access this very useful tool by clicking Server Status at the top right-hand side of
the Tomcat Web Application Manger.
When you pull up the Tomcat Web Application Manager to deploy your application,
you need to know which directory to look in to select the Web Archive (WAR) for
deployment. Use the code in Listing 11 to find this file.
bash-3.00# cd $CATALINA_HOME
bash-3.00# find . -name *.war
./webapps/docs/appdev/sample/sample.war
./webapps/sample.war
Under War file to deploy, simply click Browse. Select the sample application WAR
using the path you found above. Click Open, and then click Deploy. Really, it's as
simple as that to deploy the sample application.
As you can tell, this is just a verification that your Tomcat server was installed
correctly and is functioning as intended. To deploy your personal application, you
must follow J2EE guidelines regarding packaging and installing under certain
"context roots" under the Tomcat server directory.
Section 9. Summary
Conclusion
By now, you should be well on your way to deploying and testing your dynamic J2EE
application on your new Tomcat server! Hopefully, you learned about common Web
architecture, how to install and configure your Tomcat development server on your
UNIX operating system, and picked up some good UNIX administration tips along
the way. From here, the possibilities are endless, and there's still a lot to learn.
Best of luck!
Resources
Learn
• Read the Apache Tomcat 6.0 Application Development Guide for more
information about Tomcat installation, configuration, and features.
• The Tomcat Wiki can answer many of your additional questions regarding your
Tomcat server.
• For a great article on UNIX permissions, see "Speaking UNIX, Part 4: UNIX
ownership and permissions provide for privacy and participation" (Martin
Streicher, developerWorks, 17 Oct 2006).
• For more information about the GNU C compiler, read "Using the GNU C/C++
compiler on AIX" (Anita Govindjee, David Edelsohn, and Ramesh Chitor,
developerWorks, 12 Jan 2005).
• In the UNIX and AIX area on developerWorks, get the resources you need to
advance your skills in UNIX administration.
• Check out additional UNIX tips and tricks from the developerWorks site.
• Browse the technology bookstore for books on these and other technical topics.
Get products and technologies
• AIX comes with some good add-on toolkits specifically for developers. Other
UNIX flavors like Solaris have developer-friendly operating system installations
(for example, Solaris Express Developer’s Edition with a C compiler and lots of
other tools.
• Get more information on Sun Solaris.
• Check out FreeBSD for a free UNIX operating system.
Discuss
• Check out developerWorks blogs and get involved in the developerWorks
community.
• Participate in the AIX for Developers forum.
Lockheed Martin/United States Air Force, and WorldBank. He has multiple IBM
Certified Systems Expert certifications and received his bachelor's degree in
Computer Information Systems from Northern Arizona University. You can reach
Matthew at [email protected].
Trademarks
IBM, AIX, DB2, Tivoli, and WebSphere are trademarks of International Business
Machines Corporation in the United States, other countries, or both.
UNIX is a registered trademark of The Open Group in the United States and other
countries.
Java and all Java-based trademarks and logos are trademarks of Sun Microsystems,
Inc. in the United States, other countries, or both.
Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft
Corporation in the United States, other countries, or both.
Linux is a registered trademark of Linus Torvalds in the United States, other
countries, or both.