Configure tomcat in linux

Source: Internet
Author: User
Operating System: Redhat Linux (Fedora Core 2)
JDK: j2sdk-1_4_2_01-linux-i586.bin
TOMCAT: jakarta-tomcat-5.0.19.tar.gz

Installation steps:

JDK:
1) copy the installer to the/usr/local directory.

2) run the following command:

/J2sdk-1_4_2_01-linux-i586.bin

Decompress the package to get the directory j2sdk-1.4.2_01, change the directory name to j2sdk-1.4.2, otherwise the subsequent operation will be invalid.

3) execute the following commands in sequence:

Ln-s j2sdk-1.4.2 jdk
Ln-s jdk/jre

4) set Environment Variables

Vi/etc/profile

Add the following content:

JAVA_HOME =/usr/local/jdk
Export JAVA_HOME
CLASSPATH =/usr/local/jdk/lib:/usr/local/jre/lib
Export CLASSPATH
PATH = $ PATH:/usr/local/jdk/bin:/usr/local/jre/bin

5) test whether JDK is successfully installed.

Cd/etc
Javac

If javac instructions are displayed, the installation is successful.

TOMCAT:
1) copy the installer to the/usr/local directory.

2) run the following command:

Tar-zxvf jakarta-tomcat-5.0.19.tar.gz

Decompress the package to get the directory jakarta-tomcat-5.0.19

3) set Environment Variables

Vi/etc/profile

Add the following content:

TOMCAT_HOME = foo/tomcat
Export TOMCAT_HOME

4) enter/usr/local/jakarta-tomcat-5.0.19/bin and execute:

./Startup. sh start

Start tomcat server

5) test whether the installation is successful

Use a browser to browse http: // localhost: 8080

If the welcome page of tomcat appears, the installation is successful.

 

 

 

I suppose you use Debian3. If you use another Linux version, there may be differences between the installation method and the setting path.

1. Install J2SDK 1.1 and use the installation package in the Debian Source

Run the apt-get install sun-j2sdk1.4 as root to install sun's j2sdk1.4. Enter java. If the command is not found, the installation is correct. Otherwise, check whether there are two files: java and javac. Under/usr/lib/j2sdk1.4-sun/bin, if yes, create a link to/usr/bin, the connection name is the same as the original file name.

1.2 use the installation package on the sun website

For details, refer to the installation instructions on the sun website. You can also refer to my practices (graphic interface operation ):

Download the correct compressed package and decompress it. Generally, a folder named jdk1.x. x is obtained. Move the entire folder to the/usr/lib directory and enter jdk.1.x. create links to four executable files, java, javac, javadoc, and jar under x/bin, copy them to the/usr/bin folder, and rename them the same as the original file. The reason for this is that/usr/bin is a part of the $ PATH environment variable. In the future, you want to run the javac command to compile a variable. in the java source file, you only need to enter javac filename, instead of the complete path of the javac file.

JAVA_HOME environment variables can be left unspecified, because according to my use experience, jdk programs such as java and javac know where to find their home. When a program requires the JAVA_HOME environment variable, we can set it in its startup script. Because there are few programs that use the JAVA_HOME environment variables.

2. install Tomcat to download Tomcat for Linux from the http://tomcat.apache.org/website. The website has different versions of the source code package and Binary Package, and the Binary Package has three types: core, deployer, and embedded. I use the core in the tomcat5.28 Binary Package.

Download jakarta-tomcat-5.0.28.tar.gz unzip, will get the jakarta-tomcat-5.0.28 folder, I renamed it tomcat5, copy it to your favorite place. I put it under/usr/share.

2.1 test run tomcat

Enter/usr/share/tomcat5/bin/startup. sh in the terminal to start tomcat. Then, enter http: // localhost: 8080 or http: // 127.0.0.1: 8080 in the browser and you will see the page generated by tomcat.

Error in running/usr/share/tomcat5/bin/startup. sh? Trial run:

JAVA_HOME =/usr/lib/j2sdk1.4 _ sun # The path here is your j2sdk installation path export JAVA_HOME/usr/share/tomcat5/bin/startup. sh2.2 there are two ways to set tomcat to start upon startup: 1. Start with the built-in STARTUP script of tomcat and 2. start tomcat as a Linux Process Using jsvc.

2.2.1

Create a script named tomcat5.sh with the following content:

#! /Bin/sh # file: tomcat5.sh # Set environment variables, if it cannot be started, remove the comment # JAVA_HOME =/usr/lib/j2sdk1.4-sun # CATALINA_HOME =/usr/share/tomcat5 # CLASSPATH =\# $ JAVA_HOME/lib/tools. jar: \ # $ CATALINA_HOME/bin/commons-daemon.jar: \ # $ CATALINA_HOME/bin/bootstrap. jarcase "$1" in start) echo "Starting tomcat5... "/usr/tomcat5/bin/startup. sh; stop) echo "Stopping tomcat5... "/usr/tomcat5/bin/shutdown. sh; *) echo "Usage tomcat. sh start/stop" Exit 1; esac # tomcat5.sh end copy tomcat5.sh to/etc/init. d. Then run/usr/bin/ksysv to run the startup setting tool on the graphic interface. Drag tomcat5.sh in the Available Services column to Runlever 2 Start, Runlever 3 Start, Runlever 4 Start, Runlever 5 Start, Runlever 6 Start, Runlever 0 Stop, Runlever 1 Stop, Runlever 6 Stop, you may need to pay attention to the icon position. I drag the icon to the position where the Start Project label in each column is 90.

Or you can run:

Ln-s/etc/init. d/tomcat5.sh/etc/rc0.d/K90tomcat5. shln-s/etc/init. d/tomcat5.sh/etc/rc1.d/K90tomcat5. shln-s/etc/init. d/tomcat5.sh/etc/rc2.d/S90tomcat5. shln-s/etc/init. d/tomcat5.sh/etc/rc3.d/S90tomcat5. shln-s/etc/init. d/tomcat5.sh/etc/rc4.d/S90tomcat5. shln-s/etc/init. d/tomcat5.sh/etc/rc5.d/S90tomcat5. shln-s/etc/init. d/tomcat5.sh/etc/rc6.d/K95tomcat5. sh restart the machine to see if tomcat can be started automatically.

2.2.2

Method 2.2.1 has a serious problem, that is, tomcat has the root permission. I mean that any of your jsp scripts have the root permission, so you can easily use jsp scripts to delete things on your entire hard disk! So we 'd better not use the 2.2.1 method.

We downloaded jakarta-tomcat-5.0.28.tar.gz with the fsvc tool. In the compressed package, jakarta-tomcat-5.0.28/bin/fsvc.tar.gz. If you have followed the steps above, decompress/usr/share/tomcat5/bin/fsvc.tar.gz to get the/usr/share/tomcat5/bin/fsvc-src folder. Run on the terminal:

/Usr/share/tomcat5/bin/fsvc-src/configure -- with-java =/usr/lib/j2sdk1.4-sun

Make

Get the/usr/share/tomcat5/bin/fsvc-src/fsvc file. Copy the/usr/share/tomcat5/bin/fsvc-src/native/tomcat5.sh script file to/etc/init. d, and then use the half method in 2.2.1 to set tomcat to self-start.

/Etc/init. d/tomcat5.sh also needs to be modified to make it look like:

JAVA_HOME =/usr/lib/j2sdk1.4-sunCATALINA_HOME =/usr/share/tomcat5DAEMON_HOME =/usr/share/tomcat5TOMCAT_USER = tomcat5 # change it to the user name TMP_DIR =/var/empty = CLASSPATH = \ $ JAVA_HOME/lib/tools. jar: \ $ CATALINA_HOME/bin/commons-daemon.jar: \ $ CATALINA_HOME/bin/bootstrap. jarcase "$1" in start) # Start Tomcat # $ DAEMON_HOME/bin/jsvc-src/jsvc \...... do not restart the test. Run/etc/init manually. d/tomcat5.sh start, and then enter http:/in the browser :/ /Localhost: 8080 or http: // 127.0.0.1: 8080 check whether tomcat can be started, and then run/etc/init. d/tomcat5.sh stop to check whether it can be stopped.

Q: Why cannot I start tomcat with fsvc?

See http://jakarta.apache.org/commons/daemon/faq.html. If you use Debian, run modconf and install the capability module under/kernel/security. If you use another version and compile capability as a module, place it in the appropriate location of/etc/init. d/tomcat5.sh (Would you like to use line 2nd ?) Add modprobe capability.

3. Set the tomcat server. xml deployment website if you want to allow others to enter your IP address in the browser without adding ": Port Number" to the IP address to access your website

<Connector port = "8080" maxthreads = "150" minsparethreads = "25" maxsparethreads = "75" enablelookups = "false" redirectport = "8443" acceptcount = "100" debug =" 0 "connectiontimeout =" 20000 "disableuploadtimeout =" true "> </connector> change port =" 8080 "to port =" 80 ", because 80 is the default port requested by the browser. Find

<Host name = "localhost" debug = "0" appbase = "webapps" unpackwars = "true" autodeploy = "true" xmlvalidation = "false" xmlnamespaceaware = "false"> </ host> change to appBase = "/home/tomcatweb ". Add:

<Context path = "" docbase = "/home/tomcatweb" crosscontext = "false" debug = "0" reloadable = "true"> </context> put your own index. put jsp in the/home/tomcatweb directory, and enter http: // 127.0.0.1 in the browser. Then you can see the index. jsp running result.

4. Chinese problems tomcat has no special Chinese problems. In most cases, the problem with Chinese characters is that users do not write JSP code or even HTML code.

4.1 gibberish of simple HTML files

An HTML file containing? Zheng Shu, Xing Nai?

<Html>

4.2 simple JSP file garbled

A JSP file containing Chinese characters, such:

<% @ Page contentType = "text/html; charset = UTF-8 "%>

4.3 The content of the contained file is garbled

If your parent. use <jsp: include page = "child. jsp "> the file contains child. jsp, in parent. jsp and child. the correct <% @ page contentType = "text/html; charset = UTF-8" %> (change the UTF-8 to the correct encoding) is specified in the jsp file, the two can be different. </Jsp: include>

If your parent. use <% @ include file = "child. jsp "%> the file contains child. jsp, please ensure parent. jsp and child. jsp is the same encoding and in the parent. the correct <% @ page contentType = "text/html; charset = UTF-8" %> (change the UTF-8 to the correct encoding) is set in jsp ). Do not set <% @ page contentType = "text/html; charset = UTF-8" %> in child. jsp; otherwise, tomcat will fail (not always ).

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.