Sei sulla pagina 1di 20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

MENU

How To Install Apache Tomcat on Ubuntu


12.04
T AGGE D I N: U B U NT U , APACH E , MI SCE LLANE OU S
AU T H OR: E T E L SVE RDLOV DAT E : AB OU T 21 H OU RS AGO

About Apache Tomcat


Apache tomcat is a Java based application server released by
the Apache Software Foundation. It is a web server and a
servlet container for Java web applications.

Setup
Tomcat installation on a virtual private server is relatively easy.
Its single required dependency is Java and this tutorial will
include a step on how to install that platform.
You do need to have a user with sudo privileges for this
tutorial.

Step OneInstall Tomcat


The most recent version of Tomcat is 7, and it can be easily
downloaded through apt-get or from the Apache Tomcat site.
You can download it through apt-get by typing:
sd atgtisaltma7
uo p-e ntl oct

https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

1/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

To download tomcat from their site, copy the link for the tar.gz
package under the Core section and begin the download.
You will get a link that originates from one of Apaches many
mirrors, making the command look mostly like this (although
coming from a different site).

we ht:/irralnimtontaah/octtma-/702/
gt tp/mro.tatcer.e/pcetma/oct7v..9b

After the download completes, untar the file.


trxz aah-oct702.a.z
a vf pcetma-..9trg

Finish up the Tomcat installation on the VPS by moving the


files to a convenient directory.
sd m aah-oct702 ~pt/otma
uo v pcetma-..9 /aht/oct

Step TwoInstall Java


We installed the entire Apache Tomcat server on our virtual
server in the previous step. Before we can use it, however,
we do need to have Java installed on the VPS as well. If you
currently do not have java, you can download it quite easily
with apt-get.
sd atgtisaldfutjk
uo p-e ntl eal-d

Once you have Tomcat and Java installed on the virtual


private server, all that remains is to start them.

https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

2/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

Step ThreeConfigure .bashrc


In order to start Tomcat, we need to add it as an environment
variable in the /.bashrc file.
sd nn ~.ahc
uo ao /bsr

You can add this information to the end of the file:


epr JV_OE/s/i/v/eal-aa
xot AAHM=urlbjmdfutjv

epr CTLN_OE~pt/otma
xot AAIAHM=/aht/oct

Save and exit out of .bashrc. You can make the changes
effective by restarting the bashrc file.
.~.ahc
/bsr

Step FourRESULTS
Tomcat is now installed and configured on our virtual servers.
However, it is not yet activated.
The final step is to activate Tomcat by running its startup
script:
$AAIAHM/i/tru.h
CTLN_OEbnsatps

Once that runs, Tomcat is up and ready on port 8080.

https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

3/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

You can visually verify that Tomcat is working by accessing


your server page at your_IP_address:8080.
It should look like this
By Etel Sverdlov

Related Tutorials
How To Use Apache HTTP Server As Reverse-Proxy Using mod_proxy
Extension
How to Set Up Railo CFML Engine with Tomcat and Apache on a Debian
7 or Ubuntu 13 VPS
How To Set Up Multiple SSL Certificates on One IP with Apache on
Ubuntu 12.04
How To Use Logstash and Kibana To Centralize Logs On Ubuntu 14.04
How To Install Graylog2 And Centralize Logs On Ubuntu 14.04

Share this Tutorial


Tweet

Share

Submit

49 Comments
maiconfz November 13, 2012
Thanks!!! IT WORKS!!!
Obs.: You can access the server at [droplet-ip]:8080/ .It's
not at localhost:8080/
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

4/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

etel November 13, 2012


You're totally right! I corrected it above. Thank you!

kasongoyo November 20, 2012


what is droplet-ip? i couldnt run the server

etel November 28, 2012


Droplet IP refers to your server's IP address. DigitalOcean
servers are called Droplets.

a2165653 December 11, 2012


what is ~/path/to/tomcat ?
can you explain more?
Thanks!

etel December 11, 2012


This is the extension to where you place your tomcat file.
It is different depending on where you choose to install it.

Server January 21, 2013


Thank you for the notes. Could you explain why this
tutorial did not just use apt-get to install the tomcat7
package? Also, how can we setup tomcat to auto start on
server reboot?
Thanks!

Griffin February 3, 2013


I used the "sudo apt-get install tomcat7", and it installed
tomcat to /usr/share/tomcat7
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

5/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

It also installed the openjdk version of Java.


I did have to edit the .bashrc to add the 2 settings.
I also needed to set
CATALINA_OUT=/var/log/tomcat7/catalina.out
The problem is that tomcat then complains it doesn't have
permission to write there. How do I change the
permissions on the /var/log/tomcat7 directory?

neilh20 March 9, 2013


I used the "sudo apt-get install tomcat6", and it installed
tomcat to /usr/share/tomcat6
There was already installed an OpenJdk IcedTea6 1.12.3
java version "1.6.0_27"
When I did startup.sh - I had the same response
touch: cannot touch
`/usr/share/tomcat6/logs/catalina.out': No such file or
directory
/usr/share/tomcat6/bin/catalina.sh: 375:
/usr/share/tomcat6/bin/catalina.sh: cannot create
/usr/share/tomcat6/logs/catalina.out: Directory
nonexistent
However, trying :8080 I got "It worked" for tomcat - so
something is coming up.
So creating and fixing the
sudo mkdir /usr/share/tomcat6/logs
sudo chown user:user /usr/share/tomcat6/logs
Allowed me to
cat /usr/share/tomcat6/logs/catalina.out
and a few other directories needed creating and
populating which got me into more issues.
Then :8080 didn't even respond.
Seems to me that the basic configuration doesn't pull in a
working demo - and I'm going back to thinking about it.
I do have a working/production tomcat6 environment on
another virtual machine (that some one else setup), and
got a version up and going on a local Ubuntu 11.x some
time ago - so going to figure out what I did in those
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

6/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

environments.

vsc1981 March 14, 2013


Hi!
I have to install Tomcat in order to run my WAR file.
I have installed it using "sudo apt-get install tomcat7".
Because of the posts above I have discovered the path
where it has been installed is: "/usr/share/tomcat7"
I have added to "sudo nano ~/.bashrc" the 2 lines you
specify.
When I try to run the "$CATALINA_HOME/bin/startup.sh"
command it tells me:
"/home/MYUSER/usr/share/tomcat7/bin/startup.sh: No
such file or directory"
It adds the "/home/MYUSER/" string to the path and I
cannot execute the startup.sh, but for some reason if
write DROPLET_IP:8080 on my browser the tomcat page
appears and it seems to work.
Can you help me with this please?
Thanks in advance.

rajan0913 March 18, 2013


hi ..
i have ubuntu 12.04
i am using the eclipse indigo IDE for developing the php
projects with the xampp server
i want to use the same IDE for develop the JAVAEE
project...
but i am not able to configure both things
PLEASE give me the instructions for those things
please help me !
i am waiting for your reply ..
thanks in advance !

neilh20 March 20, 2013


Hell vsc1981 - I'm exploring some of these options as well.
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

7/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

The way I understand it, tomcat is starting up on machine


boot from /etc/init.d/tomcat
which sets user:group tomcat6 tomcat6 &
CATALINA_HOME=/usr/share/tomcat6
CATALINA_BASE=/var/lib/tomcat6
and it all works.
<<>>
sudo apt-get install tomcat6-user
tomcat6-instance-create my-instance
(answer ENTER to the question)
Now you can install your common libraries in the lib/
subdirectory and deploy your webapps in the webapps/
subdirectory. No webapps are deployed by default.
Now you need to shutdown tomcat and start my-instance
my-instance/bin/shutdown.sh
my-instance/bin/startup.sh
<<<< on startup it unpacks all your webapps/xxxx.war to
directory xxxx. now only your deployment of .war is
working>>>>
HOWEVER, I haven't figured out to do production - get it
into the startup $CATALINA_BASE.
This is supposed to be easy through the "manager"
package - but it hasn't worked for me. Maybe because I
don't have the right directory IDs for tomcat6.

neilh20 March 20, 2013


Oops - in the previous post - I'm using tomcat6 because
of a legacy app working in it - so every thing should
reference tomcat6, and my guess is tomcat7 works the
same.

manpreetsidhu88m June 12, 2013


Its good........... But where is script to start Apache
automatically at Boot time?

https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

8/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

kamal June 12, 2013


@manpreetsidhu88m do /etc/init.d/tomcat and
/etc/init.d/apache2 exist?

2011chandan July 4, 2013


I have installed tomcat7. I followed the exact process
described here for installation. I have given the path in
bash as CATALINA_HOME=/usr/share/tomcat7. But when
I'm trying to activate it using
CATALINA_HOME/bin/startup.sh, it throws No such file or
directory found.
Below are the paths that I have set in bash file:
export JAVA_HOME=/usr/lib/jvm/default-java
export CATALINA_HOME=/usr/share/tomcat7
Can anyone let me why it is happening?

kamal July 4, 2013


@2011chandan Try running
/usr/share/tomcat7/bin/startup.sh directly - does that
work?

mseanu July 10, 2013


Tell Me to configure Tomcat with php

kamal July 10, 2013


@mseanu: PHP 5 is not supported by Tomcat. Tomcat is a
java webserver, try installing Apache or Nginx to serve
PHP files:
apache:
https://www.digitalocean.com/community/articles/howhttps://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

9/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu
or
nginx:
https://www.digitalocean.com/community/articles/howto-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-1204

klimatima July 22, 2013


n00b question: i have installed tomcat on my localhost
(ubuntu12.04). i can run a war file and so forth. and can
then access it ....:8080. so, installing it on DO (it should
be similar to how i set it up on my localhost), how then
would users be able to view the app? by going to (e.g.
droplet_.com:8080) on their browser?

kamal July 23, 2013


@klimatima: Yes, that is correct.

bezvezemail July 25, 2013


I dont get a page like from a picture. I get "It works If
you're seeing this page via a web browser, it means
you've setup Tomcat successfully. Congratulations!.." but
how do I get the page from the picture?

kamal July 25, 2013


@bezvezemail: This article is a bit old so Tomcat might
have changed their default page.

sandeepbhandari1 July 29, 2013


Could you pls. also share what if we are unable to start
tomcat due to some problem and still want to know the
version of tomcat by being offline. I have searched a lot
for this but not able to find a way. The other tutorial also
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

10/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

proved of some help but still looking for answer.

kamal July 29, 2013


@sandeepbhandari1: "apt-cache show tomcat7" should
show you the package's version.

klimatima August 22, 2013


i also installed tomcat6 and when i run the
"$CATALINA_HOME/bin/startup.sh"
i get this:
-bash: /root/usr/share/tomcat6/bin/startup.sh: No such file
or directory
but when i go to 8080, i see the "it works" page, but that's
all. going to the manager webapp throws a 404 error.

kamal August 23, 2013


@klimatima: Did you follow this article properly? Please
paste the commands you ran (they're stored in
~/.bash_history).

nishapmore September 2, 2013


Hi,
I followed all the steps you have given. For more
clarification:
I run below commands ,
1) sudo apt-get install tomcat7 ( I am successfully installed
tomcat7 @ user/share/tomcat7)
2) sudo apt-get install default-jdk ( Successful java
installed @ /usr/lib/jvm/default-java)
3) sudo nano ~/.bashrc ( export
JAVA_HOME=/usr/lib/jvm/default-java
export CATALINA_HOME=/user/share/tomcat7 added at
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

11/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

end of file and saved)


4)~/.bashrc when i hit the enter after this cmd I got an
error Permission denied:(
5)$CATALINA_HOME/bin/startup.sh then I got "bash:
CATALINA_HOME/bin/startup.sh: No such file or
directory
"
6) According to post i ran
"/usr/share/tomcat7/bin/startup.sh"
and this time I got below Error log on terminal.
shani@shani-Vostro-2520:~$
/usr/share/tomcat7/bin/startup.sh
Using CATALINA_BASE: /usr/share/tomcat7
Using CATALINA_HOME: /usr/share/tomcat7
Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
Using JRE_HOME: /usr/lib/jvm/default-java
Using CLASSPATH:
/usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcatjuli.jar
touch: cannot touch
`/usr/share/tomcat7/logs/catalina.out': No such file or
directory
/usr/share/tomcat7/bin/catalina.sh: 389:
/usr/share/tomcat7/bin/catalina.sh: cannot create
/usr/share/tomcat7/logs/catalina.out: Directory
nonexistent

Please Help me!!!

kamal September 5, 2013


@nishapmore: Are you still experiencing this issue?

petersonjake September 11, 2013


export CATALINA_HOME=/user/share/tomcat7
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

12/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

I created the directory "logs" as well as the file


"catalina.out" inside it.....
droplet-ip:8080:
*******************
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/tomcat7/webapps/ROOT/index.html

kamal September 12, 2013


Great! :]

normanitc September 25, 2013


I've been working for hours trying to get this to work. If I
start up a completely new droplet, it get it to work every
time, first try. However when I try to do this on my droplet
that I've already set up with a LAMP stack, and already
have a website running with a mail server, owncloud and
all that I always get the error when I try to run
$CATALINA_HOME/bin/startup.sh. The error is:
-bash: /root/usr/share/tomcat7/bin/startup.sh: No such file
or directory
This is following the setup exactly. And like I said when I
run this on a fresh droplet it works fine.

normanitc September 25, 2013


After doing research I probably should have done before,
do you still have to do some config. to use apache2 with
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

13/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

tomcat7?

kamal September 27, 2013


@normanitc: See if this helps:
http://thetechnocratnotebook.blogspot.co.il/2012/05/installingtomcat-7-and-apache2-with.html

ichraf.bouzekri October 8, 2013


Hi nishapmore,
I have the same problem. Could you tell me if you have
risolved it ??

ayoubpats October 18, 2013


Hi
i have installed tomcat7 and openjdk and when i run the
below command it says no such file or directory
CATALINA_HOME/bin/startup.sh
-bash: CATALINA_HOME/bin/startup.sh: No such file or
directory
root@pacific:~# usr/share/tomcat7/bin/startup.sh
-bash: usr/share/tomcat7/bin/startup.sh: No such file or
directory
when i goto my ipadress:8080 it gives the below mesage
.dont know if i can go ahead and deploy my application or
not.
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:
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

14/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

/var/lib/tomcat7/webapps/ROOT/index.html
Tomcat7 veterans might be pleased to learn that this
system instance of Tomcat is installed with
CATALINA_HOME in /usr/share/tomcat7 and
CATALINA_BASE in /var/lib/tomcat7, following the rules
from /usr/share/doc/tomcat7-common/RUNNING.txt.gz.
You might consider installing the following packages, if
you haven't already done so:
tomcat7-docs: This package installs a web application that
allows to browse the Tomcat 7 documentation locally.
Once installed, you can access it by clicking here.
tomcat7-examples: This package installs a web
application that allows to access the Tomcat 7 Servlet and
JSP examples. Once installed, you can access it by
clicking

kamal October 18, 2013


@ayoubpats: It should be
$ A A I A H M / i / t r u . h not
CTLN_OEbnsatps,
CTLN_OEbnsatps
AAIAHM/i/tru.h

ivelclown October 24, 2013


Guys, is the procedure the same in installing apache2 in
red hot?

kamal October 24, 2013


@ivelclown: No. This article walks you through installing
Apache Tomcat on Ubuntu. See
https://www.digitalocean.com/community/articles/howto-install-linux-apache-mysql-php-lamp-stack-on-centos-6
on how to install Apache2 on CentOS.

https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

15/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

jamesharoldkelley November 1, 2013


I ***STRONGLY*** suggest that users also setup
CATALINA_BASE environment var while configuring
CATALINA_HOME in their .bashrc file as follows:
CATALINA_HOME=/usr/share/tomcat7
CATALINA_BASE=/var/lib/tomcat7
CATALINA_BASE contains various configurations that are
NOT properly picked up (if unset) since CATALINE_BASE
defaults to the same path as CATALINA_HOME and
things get very wonky, this would including: startup
errors, unable to find logging directories and doing
something as simple as changing Tomcat port from 8080
to 80 will fail miserably because the autobind property
(contained in a configuration file in /var/lib/tomcat7) will
be missing/improperly set. Might I suggest that this
additional step be included in the above how-to. (BTW -figuring this all out took several hours after pouring over
the tomcat manuals before stumbling onto this, while
some might have found it faster, I don't think it is at all
obvious for any newbie)
Thanks

vishal November 9, 2013


Hi,
My Tomcat Server keeps on crashing everytime I delete a
webapp or restart tomcat
In order to restart tomcat I use the following command sudo service tomcat7 restart
Can someone please help

kamal November 9, 2013


@vishal: Does it output any errors when it crashes?

https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

16/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

enterhtml November 21, 2013


Hi I'm new to this kind of installation. I followed all the
three steps exactly. But in the forth step, I don't know
what to do. I gave the path for "export
CATALINA_HOME=~/path/to/tomcat" as "export
CATALINA_HOME=~/home/MY_Name/tomcat". Now
please tell me how to run
$CATALINA_HOME/bin/startup.sh?
I enter the same "$CATALINA_HOME/bin/startup.sh" on
my terminal. It didn't work. Where to run or add this link.
Please help.

bharath.shanigarpu November 27, 2013


I have installed tomcat 7..i want to add it in startup
script..how to i add it...
Thanks in advance

kamal November 27, 2013


Does / t / n t d t m a exist?
ecii./oct

mattbaker January 9, 2014


@Kamal Nasser:
I'm getting the error:
touch: cannot touch
`/usr/share/tomcat7/logs/catalina.out': No such file or
directory
/usr/share/tomcat7/bin/catalina.sh: 389:
/usr/share/tomcat7/bin/catalina.sh: cannot create
/usr/share/tomcat7/logs/catalina.out: Directory
nonexistent
Any thoughts on fixing this are appreciated by me and
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

17/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

the others who have posted this error on this thread.


Thank you!!!

jagad1978 February 26, 2014


How can we setup tomcat to auto start on server reboot? I
installed tomcat in root (/root/apache-tomcat-7.0.52/)
Can someone please help
Thanks,
Jagadish

nguyen.h.khanh March 17, 2014


I downloaded and extract tomcat to /opt/.
I was able to start tomcat but when I tried to access
myip:8080, there is nothing. In fact, it's an error. Chrome
says it can't connect.
My terminal looks like:
knguyen@knguyen:~$ $CATALINA_HOME/bin/startup.sh
Using CATALINA_BASE: /opt/tomcat8
Using CATALINA_HOME: /opt/tomcat8
Using CATALINA_TMPDIR: /opt/tomcat8/temp
Using JRE_HOME: /usr/bin/
Using CLASSPATH:
/opt/tomcat8/bin/bootstrap.jar:/opt/tomcat8/bin/tomcatjuli.jar
Tomcat started.

rock.and.roses March 28, 2014


hi, dont work me CATALINA'S setup or run it on terminal,
but
on browser i wrote http://localhost:8080/
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

18/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

previusly on terminal :
sudo /etc/init.d/tomcat7 start
[sudo] password for user: xxxxxx
* Starting Tomcat servlet engine tomcat7

and:
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 h........

it is all right? or...?

Log In to comment

Leave a comment...

SUBMIT COMME NT

https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

19/20

12/6/2014

How To Install Apache Tomcat on Ubuntu 12.04 | DigitalOcean

This work is licensed under a Creative


Commons Attribution-NonCommercialShareAlike 4.0 International License.

Copyright 2014
DigitalOcean Inc.
Proudly Made in NY
Terms, Privacy, & Copyright
Security

C OMMUNITY
Dashboard
Overview
Tutorials
Questions
Projects
Tutorial Suggestions
Get Paid to Write

1 , 8 3 3 , 8 1 1 D ROPL E T S L AU N CH E D

https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

20/20

Potrebbero piacerti anche