2009年8月23日 星期日

安裝Tomcat6 在 Ubuntu 9.04

網路上有相關的資料,我參考了 http://hi.baidu.com/mwinvent/blog/item/535d2f12da3a2a58f819b832.html 之後發現有些問題,我做了些修改。


1 sudo apt-get install tomcat6 tomcat6-docs tomcat6-admin tomcat6-examples
2 cd /usr/share/tomcat6
3 sudo mkdir logs conf
4 cd /etc/tomcat6
5 sudo cp -R Catalina policy.d /usr/share/tomcat6/conf
6 sudo cp context.xml tomcat-users.xml catalina.properties logging.properties server.xml web.xml /usr/share/tomcat6/conf
7 cd /usr/share/tomcat6
8 sudo chmod -R 777 conf
9 export JRE_HOME='usr/lib/jvm/java-6-sun-1.6.0.14/jre'
10. sudo service tomcat6 start or sudo service tomcat6 stop

start your firefox,tap 'localhost:8080' in the URL window.You will see

It works !

If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!

This is the default Tomcat home page. It can be found on the local filesystem at: /var/lib/tomcat6/webapps/ROOT/index.html

Tomcat6 veterans might be pleased to learn that this system instance of Tomcat is installed with CATALINA_HOME in /usr/share/tomcat6 and CATALINA_BASE in /var/lib/tomcat6, following the rules from /usr/share/doc/tomcat6-common/RUNNING.txt.gz.

You might consider installing the following packages, if you haven't already done so:

tomcat6-docs: This package installs a web application that allows to browse the Tomcat 6 documentation locally. Once installed, you can access it by clicking here.

tomcat6-examples: This package installs a web application that allows to access the Tomcat 6 Servlet and JSP examples. Once installed, you can access it by clicking here.

tomcat6-admin: This package installs two web applications that can help managing this Tomcat instance. Once installed, you can access the manager webapp and the host-manager webapp.

NOTE: For security reasons, using the manager webapp is restricted to users with role "manager". The host-manager webapp is restricted to users with role "admin". Users are defined in /etc/tomcat6/tomcat-users.xml.

You cannot login as mannager or host mannager before you edit tomcat-users.xml located in /usr/share/tomcat6/conf

sudo gedit /usr/share/tomcat6/conf


<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager"/>
<role rolename="tomcat"/>
<role rolename="admin"/>
<role rolename="role1"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="admin" password="admin" roles="manager,admin"/>
<user username="role1" password="tomcat" roles="role1"/>
</tomcat-users>



改完之後要 restart Tomcat
sudo service tomcat6 restart
* Stopping Tomcat servlet engine tomcat6 [ OK ]
* Starting Tomcat servlet engine tomcat6 [ OK ]

Moreinfo at https://help.ubuntu.com/8.10/serverguide/C/tomcat.html

sudo gedit /usr/share/tomcat6/conf/server.xml
在裡面找到<connector port="80">的元素
在中間加上URIEncoding="utf-8"的屬性就可以了:
<connector port="80" protocol="HTTP/1.1" uriencoding="utf-8">