2009/05/12

Installing Apache2 and Tomcat6 on Ubuntu 9.04

I've had quite a few issues getting Apache to Tomcat to work together on Ubuntu. Finally I've figured out the little differences you need to know when using ubuntu apache and tomcat packages.
1) sudo apt-get install apache2 tomcat6 libapache2-mod-jk
2) sudo vim /etc/apache2/workers.properties
and type/past in:
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009

3) sudo vim /etc/apache2/apache2.conf
and type/past in:
# Load mod_jk module
# Update this path to match your modules location
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
# Declare the module for (remove this line on Apache 2.x)
#AddModule mod_jk.c
# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /etc/apache2/workers.properties
# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile /var/log/apache2/mod_jk.shm
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "


6) sudo vim /etc/apache2/sites-enabled/000-default
Delete "DocumentRoot /var/www"
And type in
JkMount / worker1
JkMount /* worker1

note, you can use JkUnMount to define directories you want apache to serve

7) Enable port 8009 on tomcat
sudo vim /etc/tomcat6/server.xml
remove the "<!--" that is a line above and the "-->" that is a line below
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

8) restart tomcat
sudo /etc/init.d/tomcat6 restart

9) restart apache
sudo /etc/init.d/apache2 restart

10) wget localhost
You should see the default tomcat page

18 comments:

Anonymous said...

Thanks!!!

After trying many many times following other blogs, yours puts an end to my misery! :P

Thanks a lot! Great post!

rcpeters said...

cool, glad to know it was worth posting :-)

andy brookes said...

hi

this is a great help for someone like me who can write simple jsp pages, that i have got working previously on a apache-tomcat-5.5.25 home web development set up, and also on thwe web , but wants to move to a Linux set up.

This is partly to understand a bit more about Linux because my web hosting is on a Red hat Linux. Also because Ubuntu & Linux come with great apps , such as Gimp which is worth moving over to from Paintshop pro.

I had managed to get apache2, MySQl & phpmyadmin installed so that i could access my database from http://localhost/phpmyadmin & index.html worked so I thought i was onto a winner. Then I found myjsp.jsp did not work in /var/www

I have followed your itinerary to the letter & all the jsp's (which are in /var/lib/tomcat6/webapps/ROOT) now work from: http://localhost/
so well done to you, and more power to you !

Whereas i previously had to use: http://localhost:8080/ now just about everything works
from http://localhost.

A trivial thing to add for other greenhorns is that vim was not recognised from my terminal command on Mint7, just replace the word "vim" with "gedit" , which is what I did and everything will be fine. ( incidentally "vim" is something that my mum used to use to clean the bath ,giving a gritty feel to bath useage! )


The only problem is a jsp that works on the web is giving a :

access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)

let me know if anyone can help.Theres nothing wrong with my jsp it works on the web & previously on windows/apache-tomcat-5.5.25


cheers & thanks

Unknown said...
This comment has been removed by the author.
Ram said...

Thanks Yin, I spend lot of time to configure Apache and Tomcat - but your steps are actually helpful for me to finish this integration successfully.

Vijit said...

Ahhh thanks very much. Step #6. Nobody in any of the other blogs managed to mentions the magical step #6.

Thanks again.

ateh said...

thanks!!! ;)

thangaraj said...

Nice post, really you save my time

Anonymous said...

Great, saved me some precious time.

You could keep jk-specific configuration in a jk.conf file in the mods-available directory :

JkWorkersFile /etc/apache2/workers.properties
JkShmFile /var/log/apache2/mod_jk.shm
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

- that's where my ubuntu installed a jk.load file with just the LoadModule-Directive. Then symlink "ln -s /etc/apache2/mods-enabled/jk.conf /etc/apache2/mods-available/jk.conf"

Anonymous said...

Thank you very much. saved me from going back to windows :)

Skinny Sticks said...

You are freaking brilliant. I spent a couple of hours trying to get mod_jk to work on ubuntu. I was missing that sites-enabled section. That was keeping mod_jk from starting up. 5 minutes with your help and I'm all set.

Anonymous said...

Man Thanks a LOT!!!!!!!

Francesco

Anonymous said...

I love you. You have no idea how much time I spent on this. Thank you thank you thank you thank you you're the best.

marcelo pino said...

Y Si necesito ver un sitio en php en la ruta /var/www ya no se visualiza, como lo deberia ahcer?

Anonymous said...

Thanks a lot!

Anonymous said...

Thanks rcpeters!

Even three years after posting this is the best to the point instruction I have found.

Aaron said...

Thanks for this, you just saved me a lot of frustration. Been through dozens on posts on the subject that were far more complex and difficult to follow.


Cheers!

Bivin said...

Great and excellent post, it really saved my time in configuring this. I have tried several post but it wont help me .

thanks thanks............. you are excellent

Bivin