Solved

running apache 2.2.x and tomcat 6.0.2

Posted on 2006-11-20
35
6,185 Views
Last Modified: 2010-05-18
on my laptop im running apache 2.2.x with 16 virtual hosts.  im also running PHP 5.2.x with MySQL 5.x.  I have just installed tomcat apache 6.0.2 so i can now support JSP and servlets.  Can somebody help me configure tomcat and apache so they speak and apache send tomcat apache all jsp requests etc...
0
Comment
Question by:ellandrd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 21
  • 14
35 Comments
 
LVL 19

Assisted Solution

by:ramazanyich
ramazanyich earned 500 total points
ID: 17982837
There is a nice step by step guide at
http://tomcat.apache.org/connectors-doc/howto/apache.html
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17985660
yes this is a great site - i havent fully read the whole lot, but hopefully i will later today.  i have just browsed over it quickly and it looks like what im after.

however, my understanding of how tomcat apache and apache http server work together is a little poor.

can you answer this question for me please.

when i try running a PHP page under:

w:\apache\htdocs\index.php,

apache will handle it on its own right?  but when i try running a JSP page under:

w:\apache\htdocs\index.jsp,

will apache send the request to tomcat server and retreive the results again or will i have to call the JSP from the tomcat server like:

w:\apache\tomcat\webapps\root\index.jsp

see this is where i get all confused to how it actually works??
0
 
LVL 19

Assisted Solution

by:ramazanyich
ramazanyich earned 500 total points
ID: 17987267
for PHP files you are right it will be executed inside Apache server by mod_php.

For JSP pages the Apache HTTP server doesn't do anything itself. In JkMount config line in httpd.conf (parameter of mod_jk, described in URL which I posted previously)  you can say that requests for *.jsp files will be internally redirected to Tomcat server. Tomcat server will do it's staff (JSP page compilation, execution) and response will be returned back to Apache HTTP server and it will  return it to browser.

mod_jk just makes internal TCP connectiton from Apache http server to Tomcat based on URL.
0
Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

 
LVL 16

Author Comment

by:ellandrd
ID: 17987313
much clearer now!

thank you.  i will be configuring tomcat and apache tonight as im in work at the moment...
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17991211
ok im stuck.

im as far as "Simple configuration example".  i dont know what to replace for mine to work??

also i dont have a workers.properties file either??

tomcat apache is installed under:

w:\apache\tomcat\conf
w:\apache\tomcat\bin
....
w:\apache\tomcat\webapps


and apache web server is installed under:

w:\apache\conf
w:\apache\htdocs
....
w:\apache\modules

apache wont restart for me now either??

im running apache and tomcat apache on windows xp pro sp2...
0
 
LVL 19

Assisted Solution

by:ramazanyich
ramazanyich earned 500 total points
ID: 17991359
First of all check that you downloaded correct mod_jk binary module.  For windows and Apache2.2 you can download it from this URL http://apache.scarlet.be/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.19/mod_jk-apache-2.2.3.so and put it as mod_jk.so into w:\apache\modules directory.
In file w:\apache\conf\httpd.conf add following lines:
LoadModule    jk_module  w:/apache/modules/mod_jk.so
AddModule     mod_jk.c
JkWorkersFile w:/apache/conf/workers.properties
JkLogFile     w:/apache/logs/mod_jk.log
JkLogLevel    info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat     "%w %V %T"
JkMount  /*.jsp worker1

Create file w:/apache/conf/workers.properties and put following lines there:
worker.list= worker1
worker.worker1.host=tomcat_host_name
worker.worker1.port=8007
worker.worker1.type=ajp13

replace tomcat_host_name by DNS name of your server (or IP address)

Now start tomcat and apache httpd server.
If it doesn't work send what appears in error.log file of apache server and w:/apache/logs/mod_jk.log
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17993947
should the workers.properties file be in:

w:/apache/tomcat/conf or
w:/apache/conf  

as im getting confused...

what about servlets?

>>tomcat_host_name by DNS name of your server (or IP address)

i have tomcat running on localhost port 8080 or 127.0.0.1:8080...  will this be what i have to replace with tomcat_host_name?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17993977
i still cant get apache httpd server to start.

tomcat apache starts fine.

i had to comment out this lines to get apache httpd server:

LoadModule jk_module w:/apache/modules/mod_jk.so
#AddModule mod_jk.c
#JkWorkersFile w:/apache/tomcat/conf/workers.properties
#JkLogFile w:/apache/logs/mod_jk.log
#JkLogLevel info
#JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
#JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
#JkRequestLogFormat "%w %V %T"
#JkMount /*.jsp worker1

i have created the workers.properties file and stored it in w:/apache/tomcat/conf/workers.properties.

i have noticed there is other *.properties files inn that directory too...

in my logs folder i have this: (error.log)

[Wed Nov 22 08:40:05 2006] [notice] Apache/2.2.3 (Win32) PHP/5.2.1-dev mod_jk/1.2.19 configured -- resuming normal operations
[Wed Nov 22 08:40:05 2006] [notice] Server built: Jul 27 2006 16:49:49
[Wed Nov 22 08:40:05 2006] [notice] Parent: Created child process 2876
PHP Warning:  PHP Startup: java: Unable to initialize module\nModule compiled with module API=20060613, debug=0, thread-safety=1\nPHP    compiled with module API=20050922, debug=0, thread-safety=1\nThese options need to match\n in Unknown on line 0
[Wed Nov 22 08:40:06 2006] [notice] Child 2876: Child process is running
[Wed Nov 22 08:40:06 2006] [notice] Child 2876: Acquired the start mutex.
[Wed Nov 22 08:40:06 2006] [notice] Child 2876: Starting 250 worker threads.
[Wed Nov 22 08:40:07 2006] [notice] Child 2876: Starting thread to listen on port 80.
0
 
LVL 19

Assisted Solution

by:ramazanyich
ramazanyich earned 500 total points
ID: 17993982
It seems there is a conflict between php module and mod_jk modules because they compiled for different versions.
Just for clarification of the problem try to disable mod_php and enable back mod_jk parameters and see if communication with tomcat goes ok.
If it is a case we can check further.
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17993992
ok ive commented this line out and now apache httpd server wont start...

#LoadModule php5_module "W:/PHP/php5apache2_2.dll"
0
 
LVL 19

Expert Comment

by:ramazanyich
ID: 17994007
you should comment out all php related config lines, because it is not only LoadModule.
0
 
LVL 19

Expert Comment

by:ramazanyich
ID: 17994008
could you send your httpd.conf file ?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17994011
ok 2 secs
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17994016
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17997625
did you get my httpd.conf file?
0
 
LVL 19

Expert Comment

by:ramazanyich
ID: 17998297
yes I did, but don't see anything wrong in it.
Maybe something in included conf file  conf/extra/httpd-vhosts.conf ?
Do you syill have the same error in log file ?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17998432
yes
0
 
LVL 19

Expert Comment

by:ramazanyich
ID: 18001179
could you send contents of   conf/extra/httpd-vhosts.conf file too ?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18001440
0
 
LVL 19

Accepted Solution

by:
ramazanyich earned 500 total points
ID: 18001751
I checked files - they are correct.
So what I did now is tested my solution myself.
I downloaded apache2.2.3 from http://apache.belnet.be/httpd/binaries/win32/apache_2.2.3-win32-x86-no_ssl.msi
downloaded tomcat6.0.2  from http://apache.scarlet.be/tomcat/tomcat-6/v6.0.2/bin/apache-tomcat-6.0.2.zip 
and mod_jk1.2.19 from http://apache.scarlet.be/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.19/mod_jk-apache-2.2.3.so

Installed and started apache on port 80 and accessing http://localhost:80 was ok.
Unpacked tomcat and started it. Accessing http://localhost:8080/examples/jsp/jsp2/el/basic-arithmetic.jsp went ok.

now I put mod_jk.so into $APACHE_HOME/modules directory (renamed mod_jk_apache2.2.3.so to mod_jk.so)

Tried my suggested config and indeed it didn't work. I had to do two adjustments.
Now correctly working config on myh PC is looking like that:
httpd.conf:
LoadModule    jk_module  modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile     logs/mod_jk.log
JkLogLevel    info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat     "%w %V %T"
JkMount  /*.jsp worker1

as you can see AddModule directive is deleted

workers.properties:
worker.list= worker1
worker.worker1.host=tortuga
worker.worker1.port=8009
worker.worker1.type=ajp13

port number changed from 8007 to 8009

now I can access both
http://localhost/examples/jsp/jsp2/el/basic-arithmetic.jsp
and http://localhost:8080/examples/jsp/jsp2/el/basic-arithmetic.jsp


0
 
LVL 16

Author Comment

by:ellandrd
ID: 18004737
see this worker.properties file - where do i put this? in:

w:/apache/conf

or

w:/apache/tomcat/conf

??

also see the content of the worker file:

worker.list= worker1
worker.worker1.host=tortuga  <<------------ do i change this to 127.0.0.1:8080 or 127.0.0.1
worker.worker1.port=8009
worker.worker1.type=ajp13

>>port number changed from 8007 to 8009

why?  will have i have to change mine??
0
 
LVL 19

Assisted Solution

by:ramazanyich
ramazanyich earned 500 total points
ID: 18005053
worker.properties file should be put to w:/apache/conf/ directory.
tortuga is my hostname. So you should use yours, try localhost

and also you should use port 8009 - it is a port of JK Connector of Tomcat.
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18006330
ok apache httpd server is running on localhost port 80 and tomcat apache is running on localhost port 8080 so which port? apache httpd or tomcat server?
0
 
LVL 19

Assisted Solution

by:ramazanyich
ramazanyich earned 500 total points
ID: 18006376
maybe more clarification.
communication between apache httpd  and tomcat server is gowing using AJP protocol. It is a TCP based protocol. So it means that in Tomcat there is special TCP server is started (configured in $tomcat_home/conf/server.xml and by default it is listening on port 8009 in tomcat4.x,5.x, 6.x) and in workers.properties you specify with port by parameter worker.worker1.port. That's why you should put 8009 there.
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18006402
ok but do i put localhost as host or localhost:8080 ?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18006411
i can get tomcat running on localhost:8080 fine and i can get apache running on localhost fine, but still cant get tomcat and apache to work together...

here is my httpd.conf file part:

LoadModule    jk_module  modules/mod_jk.so
JkWorkersFile w:/apache/conf/workers.properties
JkLogFile     w:/apache/logs/mod_jk.log
JkLogLevel    info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat     "%w %V %T"
JkMount  /*.jsp worker1


in my workers.properties files in w:/apache/conf/workers.properties i have this:

worker.list=worker1
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.type=ajp13


the ajp section in my server.xml file looks like this:

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18006418
and when i start tomcat i get this:

24-Nov-2006 08:48:09 org.apache.catalina.core.AprLifecycleListener lifecycleEve
t
INFO: The Apache Tomcat Native library which allows optimal performance in prod
ction environments was not found on the java.library.path: C:\Java\jdk1.6.0\bin
.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:
WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:
WINDOWS\system32;C:\WINDOWS;%CATALINA_HOME%\bin\startup;C:\Java\jdk1.6.0\bin;C:
Java\ant\bin;C:\PHP\;W:\Perl\bin\perl.exe\;W:\OpenSSL\bin\;
24-Nov-2006 08:48:09 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
24-Nov-2006 08:48:09 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 621 ms
24-Nov-2006 08:48:09 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
24-Nov-2006 08:48:09 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.2
24-Nov-2006 08:48:09 org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
24-Nov-2006 08:48:10 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
24-Nov-2006 08:48:10 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
24-Nov-2006 08:48:10 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=10/20  config=null
24-Nov-2006 08:48:10 org.apache.catalina.startup.Catalina start
INFO: Server startup in 921 ms

0
 
LVL 16

Author Comment

by:ellandrd
ID: 18006421
and when i do this:  http://localhost/examples/servlets/

i get 404 page not found...
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18006428
i got JSP pages working... sorry it was my own stupidy!

how about serlvets?


0
 
LVL 16

Author Comment

by:ellandrd
ID: 18006482
and another thing i dont understand and im hoping you'll clear up is do i have to put all my .jsp pages under exmaples directory on tomcat apache server or can i put them under:

w:/apache/htdocs/jsp/

if so how come i cant get them to work?  the message i get is this:

HTTP Status 404 - /jsp/index.jsp

type Status report

message /jsp/index.jsp

description The requested resource (/jsp/index.jsp) is not available.
Apache Tomcat/6.0.2


also how can i get servlets working?
0
 
LVL 19

Expert Comment

by:ramazanyich
ID: 18006485
for servlets you should add additional JkMount config line based on URL path.
for example to make path /examples/servets to redirect to Tomcat add in httpd.conf file:

JkMount /examples/servlets/*
0
 
LVL 19

Assisted Solution

by:ramazanyich
ramazanyich earned 500 total points
ID: 18006487
oops didn't typed correctly
JkMount /examples/servlets/* worker1

restart apache and you should be able to access
http://localhost/examples/servlets/...
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18006498
ok last question before i accept - can you clear up thist please:

11/24/2006 09:14AM GMT

0
 
LVL 19

Assisted Solution

by:ramazanyich
ramazanyich earned 500 total points
ID: 18006576
Ok, let's explain more :)

Apache httpd server doesn't handle JSP pages by himself. It just do communication using mod_jk to tomcat server which can handle JSP pages and servlets using JkMount config line.
JkMount /*.jsp worker1
says that all requests to URLs which end with .jsp will be forwarde to Tomcat server and handled by Tomcat server (mod_jk in Apache httpd will do communication to Tomcat) and returned response from Tomcat will be returned to browser by Apache httpd.

If I can draw it here:

[browser] -- /...jsp --> [apache httpd][mod_jk] --- tcp to tomcat --->    [tomcat] -- handle request to JSP page ---
              <--- HTML response --- [apache][mod_jk] <-HTML response--                                                                                      

So there is no sense to put JSP pages to document tree (htdocs dir by default) of apache httpd server.

All JSP pages  should be managed by Tomcat server. So they have to be placed to root dir of tomcat server.(by default it is a $tomcat_home/webapps/ROOT directory)
For servlets it is more complex: you should create web applications archives (WAR files) in special structure (with web.xml, etc) and put them into $tomcat_home/webapps folder.  But more details about it is a question into another topic I suppose :).

some example web applications are packaged into tomcat server (in $tomcat_home/examples/ folder ..)


0
 
LVL 16

Author Comment

by:ellandrd
ID: 18006592
thank you for all your help and patience with me.

your explanations where great!

ellandrd
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question