How do I run PHP and Tomcat on the same server environment?

Asked about this on AskUbuntu a while ago: https://askubuntu.com/questions/630897/apache-httpd-backed-by-both-tomcat-and-php but there are no answers, so I decided to ask here.

Once again - let's say I have a server accessible for some domain name, for example. http://mywebapp.com/

I would like to configure the following on this server:

  • all requests such as http://mywebapp.com/blog*

    are processed by the server PHP

    (especially for the Wordpress blog engine).
  • all other requests are http://mywebapp.com/*

    processedApache Tomcat

I thought this could be achieved by putting the server Apache HTTPD

in front of the servers Tomcat

and PHP

but couldn't find any configurations to do this.

Can someone please give us some hint on how to do this?

+3


source to share


1 answer


You can do it with mod_jk:

1) Enable mod_jk module on your Apache httpd.conf web servers. Uncomment this line by removing the leading hash:

LoadModule jk_module modules/mod_jk.so

      

If you are using Linux type:

sudo apt-get install libapache2-mod-jk
sudo a2enmod jk

      

2) Edit [TOMCAT_DIR] /conf/server.xml. Add the "jvmRoute" attribute to the "engine" element:

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat">

      



Uncomment the AJP connector (http connector can be disabled):

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

      

3) Create a file "employees.properties" next to "httpd.conf". Add this content and set the correct ip / port:

worker.list=tomcat

worker.tomcat.type=ajp13
worker.tomcat.host=127.0.0.1
#This is the port from the AJP connector, not HTTP!
worker.tomcat.port=8009
worker.tomcat.lbfactor=10

      

4) Add this mapping to the end of your httpd.conf and replace [PATH_TO_DIR] with an absolute path:

<IfModule jk_module>

  JkWorkersFile [PATH_TO_DIR]\workers.properties
  JkLogFile [PATH_TO_DIR]\mod_jk.log 
  JkLogLevel INFO 
  JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories 

  SetEnvIf Request_URI "/error/*" no-jk
  SetEnvIf Request_URI "/blog*"   no-jk

  JkMount    /                    tomcat
  JkMount    /*                   tomcat

</IfModule>

      

5) Start Tomcat and restart Httpd.

+3


source







All Articles