Since it is Ubuntu, you must make good use of the "Synaptic Package Manager".
1. Tomcat requires the support of jdk, so let’s talk about the installation of jdk first. If you have already installed jdk, you can go to item 2 directly.
1.1Install jdk
Search "sun-java" in Synaptic, install the latest jdk, such as "sun-java6-jdk", and then click Apply to automatically install it.
1.2 Configure jdk environment variables. The installation is automatic, but the configuration needs to be done by yourself.
1.2.1 Modify user environment variables
$ vi /home/fancy(your username)/.bashrc
Add: to the .bashrc file:
export JAVA_HOME="/usr/lib/jvm/java-6-sun" export CLASSPATH="$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib" export PATH="$PATH:$JAVA_HOME/bin"
1.2.2 Modify the environment variables of all users
$sudo vi /etc/profile
In this file add:
export JAVA_HOME="/usr/lib/jvm/java-6-sun" export CLASSPATH="$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib" export PATH="$PATH:$JAVA_HOME/bin"
2. Tomcat installation and configuration, here is the key 2.1 Install Tomcat through Synaptic
Not much to say about this, just search for "tomcat", select the corresponding software package and apply it.
2.2 Tomcat configuration This is the key point.
$sudo vi /etc/profile
join in:
export CATALINA_HOME="/usr/share/tomcat5.5"
Notice:
a. Some places on the Internet say that TOMCAT_HOME is set, which is incorrect;
b. It is also said on the Internet that conf/server.xml and web.xml need to be modified. This is not necessary when installing using Synaptic in Ubuntu (of course, you can change it when needed in the future, but during the first installation not required).
OK, the configuration is complete. Restart! The changes to /etc/profile will not take effect until the computer is restarted.
3. Start Tomcat service 3.1 and enter /usr/share/tomcat5.5/bin. You can see several bash scripts inside. Use
$./startup.sh
You can start the service.
Note that the tomcat here does not need to install apache and can be used directly as a web server.
The result of running ./startup.sh should be:
Using CATALINA_BASE: /usr/share/tomcat5.5 Using CATALINA_HOME: /usr/share/tomcat5.5 Using CATALINA_TMPDIR: /usr/share/tomcat5.5/temp Using JRE_HOME: /usr/lib/jvm/java-6-sun
3.2 When running ./startup.sh, you may have the following problems:
touch: cannot touch `/usr/share/tomcat5.5/logs/catalina.out': Permission denied ./catalina.sh: 323: cannot create /usr/share/tomcat5.5/logs/catalina.out
The reason is that the logs directory does not have enough permissions after installation. You can change it like this:
$ sudo chmod 766 ./logs -R
4. Check whether the service is successfully opened. Open your browser and enter: localhost:8180.
The default port of Tomcat is 8180. You can modify it in conf/server.xml so that you can directly access localhost in the future.
If the service is started normally, you will see Tomcat's navigation homepage.
5. Close the service and run shutdown.sh under bin/.
$./shutdown.sh
Normally the following results will appear:
Using CATALINA_BASE: /usr/share/tomcat5.5 Using CATALINA_HOME: /usr/share/tomcat5.5 Using CATALINA_TMPDIR: /usr/share/tomcat5.5/temp Using JRE_HOME: /usr/lib/jvm/java-6-sun
Tomcat self-starting setting tips
After installing Tomcat 5.5, it is very simple. Unzip the downloaded installation file package and put it into the corresponding directory. Then set the corresponding environment variables such as JAVA_HOME, CATALINA_HOME and other environment variables in the Linux environment and execute it in the bin directory of Tomcat. /catalina.sh run can start the tomcat service in terminal mode. If you need to add tomcat to the self-starting queue, you need to perform the following operations:
Log in to the system as root user:
cd /etc/rc.d/init.d/ vi tomcat
The file content is referenced as follows:
#!/bin/sh## tomcat: Start/Stop/Restart tomcat## chkconfig: 2345 80 20# description: Tomcat is a Java Servlet Container### match these values to your environment:export CATALINA_BASE=/usr/local/ tomcatexport CATALINA_HOME=/usr/local/tomcatexport CATALINA_TMPDIR=/usr/local/tomcat/tempexport JRE_HOME=/usr/java/jdk15# Source function library.. /etc/rc.d/init.d/functionsTOMCAT=/usr/local/tomcatstart() {echo -n $ "Starting Tomcat: "$TOMCAT/bin/catalina.sh start}stop() {echo -n $"Stopping Tomcat: "$TOMCAT/bin/catalina.sh stop}# See how we were called.case "$1" instart)start;;stop)stop;;status);;status);;restart)stopstart;;*)echo $" Usage: $0 {start|stop|restart}";;esacexit $RETVAL
Modify tomcat into a executable file. The command reference is as follows:
chmod a+x tomcat
Use the chkconfig command to add the tomcat command to the system startup queue:
chkconfig --add tomcat
Check the status of apachectl:
chkconfig --list tomcat
Okay, it’s all done. It’s a very simple record. I hope it can help you and let me remember it myself!