How to install Tomcat 6 on Ubuntu 9.04 (Jaunty)
Because Tomcat version 6 was included in Ubuntu 9.04, installing a working Tomcat server is reasonably straightforward. However, before we can start installing Tomcat itself, we must first install Java.
First Install Sun Java in ubuntu 9.04 using this tutorial
Install tomcat 6 in ubuntu 9.04
sudo apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-user tomcat6-docs tomcat6-examples
This command downloads and install the following packages
tomcat6 : Servlet and JSP engine
tomcat6-admin : Admin web applications
tomcat6-common : Common files
tomcat6-user : Tools to create user instances
tomcat6-docs : Example web applications
tomcat6-examples : Example web applications
To start, stop, restart and get the server status
Start tomcat server
sudo /etc/init.d/tomcat6 start
Stop tomcat server
sudo /etc/init.d/tomcat6 stop
Restart tomcat server
sudo /etc/init.d/tomcat6 restart
Get tomcat server status
sudo /etc/init.d/tomcat6 status
After installation type http://localhost:8080 or http://serverip:8080/examples/servlets/ in your browser.Now you should see tomcat welcome page
* To enable admin web based features add the following lines to your /etc/tomcat6/tomcat-user.xml
<user name="admin" password="secret_password" roles="manager,admin"/>
* you should be able to see your manage page here http://your_ip_goes_here:8080/manager/html
* log in with the name and password you just set in /etc/tomcat6/tomcat-users.xml
* ls /var/lib/tomcat6 directory.
* you should see these directories conf, logs, webapps, work
* webapps is where your servlets will go ( or at least a xml file that points to them )
* as a test download this war file http://simple.souther.us/SimpleServlet.war
* then use the tomcat management page and select war file to deploy ( in teh deploy section) to upload this file to your server
* optionally just wget http://simple.souther.us/SimpleServlet.war directly to the webapps folder
* tomcat should recognize the war file and expand it with everything you need
* browse to http://serverip:8080/SimpleServlet/
Change tomcat server to run on port 80
If you want to Change tomcat server to run on port 80 follow this procedure
You need to edit the /etc/tomcat6/server.xml file
Now replace the part that says Connector port=”8080? with Connector port=”80?
Save and exit the file
Restart tomcat server with the following command
sudo /etc/init.d/tomcat6 restart
Don’t forget “tasksel.” The following will install the Tomcat server, exactly as if you had selected it (configuration and all) from the menu using Ubuntu Server edition (great for installing it on K/Ubuntu desktop systems):
sudo tasksel install tomcat-server
There is a minor typo in your Howto:
Great howto anyways, cheers
Thanks for your comment i have updated the main article
I can’t open
error message says:
“You do not have the permissions necessary to open the file.”
Help please. Thanks!
You need to use sudo.
$ sudo /etc/tomcat6/tomcat-users.xml
and also it should be
Missed some due to the chars.
user USERname=”admin” password=”secret_password” roles=”manager,admin”/
I modify as specified on your instruction for the tomecat-users.xml (fixed the user username= as well) but when i tried to login to the page it does not recognize the username admin and the password i set. kept coming to prompt username and password.. any clue? i am using firefox and also restarted the tomcat services dozen times.
You probably forgot to remove the XML comment markup from around the users and roles.
While I am changing the Username and Password in Tomcat6. It is saying that i don’t have permission to write that file. when I open /etc/tomcat6/tomcat-users.xml with sudo command. It is saying “Command not found”.
Even I am not able to open tomcat-users.xml file. They is a cross mark at the top corner of the file.please help me I want to start Tomcat on ubuntu. So that I show my friends that everything happens on ubuntu!
Rahul, have you tried: sudo nano /etc/tomcat6/tomcat-users.xml
thanks for the article, it helps me!
I could see admin and management interface for the default tomcat instance. But, how to configure admin and management interface for tomcat user instance which is created by tomcat6-instance-create myinstance command. I don’t see management and admin interface for my user tomcat instance.
I have added the roles and user, after restarting tomcat I can’t even access http://localhost:8080/ it just keeps loading forever. commenting out all users and restarting tomcat makes tomcat available again, but then i can’t run the manager.
Sorry my bad, typeo in xml
Spectacular guide! I’m completely new to Tomcat, and this got me up and running immediately. Thanks for the help.
I modified the server.xml file for the Connector as stated:
Now replace the part that says Connector port=”8080″ with Connector port=”80″
But now I just get the Apache default page at http://localhost and cannot access the examples, docs, etc. by browsing to http://localhost/examples/ or http://localhost/docs/
@Ivan, I found that that didn’t not work for me either. What I found is to first undo the change you made in the server.xml file and do this…
# install the iptables applications if they are not already there
apt-get -y install iptables
# tell iptables to forward incoming requests on port 80 to tomcat
/sbin/iptables -t nat -I PREROUTING -p tcp –dport 80 -j REDIRECT –to-port 8080
after I did this every thing worked great
BTW thanks for this article, it was a great help
you have to use sudo when running those commands
Suggestion for running on port 80 (tested on tomcat6 + ubuntu server 10.04 LTS).
– edit server.xml as above to change to port 80
– edit /etc/default/tomcat6 & change last line to:
stop & restart server. Should then serve from port 80. Doesn’t need anything else (e.g. no iptables forwarding).
Using CentOS and tomcat 5.5. that file doesn’t exist in the default folder for me.
Sorry to hear that. Afraid I’m not familiar with RPM-based distros including CentOS. From a quick googling jsvc seems to be the preferred approach to enabling port 80 on CentOS. Also a good description here: http://blogs.mulesoft.org/a-better-tomcat-for-ubuntu-and-debian/
Thanks for the reply but after a quick thought I have decided to go down the headache route of using iptables to forward to the tomcat port.
Thanks a lot !!! This helped a lot.
thanks for helping this site
type the following lines than you can open
# gedit /etc/tomcat6/tomcat-users.xml
First of all, this is a great howto. I have installed tomcat6 and it is running fine. Could you help me to run a CGI script on it? I have put my cgi script in /var/lib/tomcat6/webapps/WEB-INF/cgi.
The WEB-INF was not there, so also the cgi, i made these directories with sudo. Any sort of help will always be appreciated.