9

I recently got projects that runs on Struts and I am expecting more JSP coming ahead.

After googling the question, I was led to blogs of people who tried to do the same. Those blogs weren't exactly a step by step procedure of how they did it but more like a reference in case they need to do something the same in the future. In some cases, the author didn't exactly say if he was successful in his attempt to run both aforementioned services together.

Unfortunately, I can't follow their "instructions" as I have plenty of PHP projects configured (upload directories, classpaths etc...) to run on my test server and I don't have the luxury of time to reconfigure them all in case I mess up with the httpd server. And for honesty's sake, I haven't tried a single step on running them together for the same reason of being hesitant to update configuration files.

I'm not sure if this adds to the complexity but I am running both services thru xampp (with tomcat being a xampp add-on) for portability purposes.

I know that I can just stop my Apache service whenever I am working on JSP but hey this is an oppurtunity to try something new and I just can't let it slip. Further, it would really be convenient for both services to just run automatically on startup which would really increase my productivity as I won't have to manually switch between services when needed.

Hope there's someone on SO who rode the same boat.

edit: Tomcat Version is 6.0.20 Httpd Version is 2.2.14

lock
  • 6,404
  • 18
  • 58
  • 76
  • It's a very common thing to do this, I'm a little surprised you've had a hard time finding instructions. I wish I remembered which instructions I followed when I did it myself. – David Z Aug 17 '10 at 01:52
  • ah yes i believe there are a lot of discussions going on but company internet policies blocks message boards. thank God that SO isn't considered a public forum hehe – lock Aug 17 '10 at 04:42

3 Answers3

8
  • Have Tomcat listen on a port other than 80
  • Follow a guide to set up mod_proxy to redirect requests for a certain location to Tomcat, such as this one.

If you're really just testing, skip the second step and just access the server via a different port for Tomcat.

edit: See also http://httpd.apache.org/docs/2.2/mod/mod_proxy_ajp.html on setting up mod_proxy_ajp.

Borealid
  • 95,191
  • 9
  • 106
  • 122
  • Suggest labeling `STEP 1` and `STEP 2 (optional)`. And explaining that in one alternative the site appears unified (steps 1 & 2). And the other fragmented (step 1), with different port numbers in the browser address bar. (Assuming this is all correct of course; it's like my fourth guess so far.) – Bob Stein Aug 14 '14 at 14:30
1

You neglected to mention what version of Tomcat you're using and you also didn't mention whether you actually looked at the Tomcat documentation to answer the question.

I'd suggest starting here: http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html and look into setting up mod_jk.

user334583
  • 55
  • 1
  • Note that the mod_jk(2?) method is widely considered deprecated on modern versions of Apache which come with mod_proxy_ajp. – Borealid Aug 17 '10 at 02:06
  • its Apache 2.2.14 for httpd and Tomcat 6.0.20 :) also modified the question just in case – lock Aug 17 '10 at 04:45
  • 1
    mod_jk2 was dropped ages ago. the documentation link i provided was the most up-to-date documentation on the tomcat website...which is mod_jk1.2.30 (released in Feb. of this year)....hardly deprecated and works will all versions of Apache. – user334583 Aug 18 '10 at 01:55
0

If you want to use apache/ httpd to serve the request from PHP as well as any other server running on different port let say tomcat on port 8080 you can use apache/ httpd to act as a "proxy" and map a URL which will be served by another server. This is done using ProxyPass ProxyPassReverse configuration.

For example: If you want http://localhost/php to be served by PHP and http://localhost/tomcat to be served by tomcat then you will have to make following changes in httpd.config/ apache.config [apache2.config depending on version of apache you are using]:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
# Uncomment these to proxy FTP or HTTPS
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so

<VirtualHost *:80>
# Your domain name
# ServerName Domain_NAME_HERE

ProxyPreserveHost On

ProxyPass /tomcat http://localhost:8080/
ProxyPassReverse /tomcat http://localhost:8080/

# The location of the HTML files, and access control information
DocumentRoot /var/www
<Directory /var/www>
    Options -Indexes
    Order allow,deny
    Allow from all
</Directory>

</VirtualHost>

In case you are running httpd on centos and you may get error Apache Mod_proxy '[Error] (13)Permission Denied', then follow this link which says execute the following command:

 /usr/sbin/setsebool -P httpd_can_network_connect 1

I would recommand you to read mod_proxy.

Ref: Redhat mod_proxy configuration

Vishrant
  • 15,456
  • 11
  • 71
  • 120