Advertisement
shokti

Ubuntu 12.04 - Install Tomcat 7

Sep 19th, 2012
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.12 KB | None | 0 0
  1. Install JDK 7 -- see my JDK 7 installation post.
  2.  
  3. download package by going to http://tomcat.apache.org/download-70.cgi or using command below:
  4.     wget http://www.trieuvan.com/apache/tomcat/tomcat-7/v7.0.30/bin/apache-tomcat-7.0.30.tar.gz
  5.  
  6. unpack the package:
  7.     tar xvzf apache-tomcat-7.0.30.tar.gz
  8.  
  9. move and rename directory:
  10.     sudo mv apache-tomcat-7.0.30/ /usr/share/tomcat7
  11.  
  12. define the environment variables JAVA_HOME and JRE_HOME. edit /etc/environment file:
  13.     sudo nano /etc/environment
  14.  
  15. record the routes where we have installed Java:
  16.     add the following entry:
  17.         JAVA_HOME="/usr/lib/jvm/jdk1.7.0"
  18.         JRE_HOME="/usr/lib/jvm/jdk1.7.0/jre"
  19.     append java path to the PATH environment variable:
  20.         PATH="...(other path):$JAVA_HOME:$JRE_HOME"
  21.  
  22. add routes to catalina.sh:
  23.     sudo nano /usr/share/tomcat7/bin/catalina.sh
  24.  
  25. insert the JAVA_HOME and JRE_HOME after the first line. it looks like below:
  26.     #!/bin/sh
  27.     JAVA_HOME="/usr/lib/jvm/jdk1.7.0"
  28.     JRE_HOME="/usr/lib/jvm/jdk1.7.0/jre"
  29.     # Licensed to the Apache Software Foundation (ASF)...
  30.     #...
  31.     #...
  32.  
  33. configure Tomcat users, this is done in the file "tomcat-users.xml"directory tomcat7/conf. Command to edit the file:
  34.     sudo nano /usr/share/tomcat7/conf/tomcat-users.xml
  35.  
  36. administrator should own role "manager-gui"to operate on the web administration tomcat7. The file would be as follows:
  37.     <?xml version='1.0' encoding='utf-8'?>
  38.  
  39.     <tomcat-users>
  40.     <role rolename="manager-gui"/>
  41.     <role rolename="manager-script"/>
  42.     <role rolename="manager"/>
  43.     <role rolename="admin-gui"/>
  44.     <role rolename="admin-script"/>
  45.     <role rolename="admin"/>
  46.  
  47.     <user username="tomcat" password="secret" roles="manager-gui,admin-gui,manager,admin,manager-script,admin-script"/>
  48.     </tomcat-users>
  49.  
  50. start server command:
  51.     sudo /usr/share/tomcat7/bin/startup.sh
  52.  
  53. to check if tomcat7 is running properly:
  54.     http://127.0.0.1:8080/
  55.  
  56. to access tomcat administration manager:
  57.     http://127.0.0.1:8080/manager/html
  58.  
  59. to run java samples:
  60.     http://127.0.0.1:8080/examples/
  61.  
  62. stop server command:
  63.     sudo /usr/share/tomcat7/bin/shutdown.sh
  64. ----------------------------------------------------------------------------------------
  65. Automatic Starting
  66.  
  67. To make tomcat automatically start when we boot up the computer, you can add a script to make it auto-start and shutdown.
  68.  
  69.     sudo gedit /etc/init.d/tomcat7
  70.  
  71. Now paste in the following:
  72.  
  73. # Tomcat auto-start
  74. #
  75. # description: Auto-starts tomcat
  76. # processname: tomcat
  77. # pidfile: /var/run/tomcat.pid
  78.  
  79. case $1 in
  80. start)
  81. sh /usr/share/tomcat7/bin/startup.sh
  82. ;;
  83. stop)
  84. sh /usr/share/tomcat7/bin/shutdown.sh
  85. ;;
  86. restart)
  87. sh /usr/share/tomcat7/bin/shutdown.sh
  88. sh /usr/share/tomcat7/bin/startup.sh
  89. ;;
  90. esac
  91. exit 0
  92.  
  93. You’ll need to make the script executable by running the chmod command:
  94.     sudo chmod 755 /etc/init.d/tomcat7
  95.  
  96. The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.
  97.     sudo ln -s /etc/init.d/tomcat7 /etc/rc1.d/K99tomcat
  98.     sudo ln -s /etc/init.d/tomcat7 /etc/rc2.d/S99tomcat
  99.  
  100. Tomcat should now be fully installed and operational.
  101.     sudo /etc/init.d/tomcat7 restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement