Solved

running apache 2.2.x and tomcat 6.0.2

Posted on 2006-11-20
35
6,178 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
  • 21
  • 14
35 Comments
 
LVL 19

Assisted Solution

by:ramazanyich
ramazanyich earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
you should comment out all php related config lines, because it is not only LoadModule.
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
could you send your httpd.conf file ?
0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
ok 2 secs
0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
did you get my httpd.conf file?
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
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
Comment Utility
yes
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 19

Expert Comment

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

Author Comment

by:ellandrd
Comment Utility
0
 
LVL 19

Accepted Solution

by:
ramazanyich earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
ok but do i put localhost as host or localhost:8080 ?
0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
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
Comment Utility
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
Comment Utility
and when i do this:  http://localhost/examples/servlets/

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

Author Comment

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

how about serlvets?


0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thank you for all your help and patience with me.

your explanations where great!

ellandrd
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now