How to run PHP applications in Tomcat 7 with PHP-Java bridge?

Sometimes Java hosting clients need ability to combine their Java code with PHP code. This is sometimes done by leaving PHP code in a directory under Apache Document Root (e.g. ~/public_html/drupal) and excluding requests to it from being passed to a Java application server e.g. Tomcat. It is helpful in separating Java and PHP applications running within 1 hosting account and static data like images, CSS, JavaScript. But there are cases when you need much closer integration of Java and PHP.

In this short tutorial we will show you how to use PHP-java bridege in JVM Host’s Java hosting environment. We assume you already have a Tomcat account ready for use. Let’s go!

Download JavaBridgeTemplate621.war. Optionally get from the above location. It includes full JavaBridge.war with documentation and sources.

Put the JavaBridgeTemplate621.war into your Tomcat’s webapps directory To test for excecution of Java code put into webapps/JavaBridgeTemplate62/getjavaproperties.php:

echo str_replace(",","<br/>",java("java.lang.System")->getProperties()); 

To use system php, modify webapps/JavaBridgeTemplate62/WEB-INF/web.xml and make sure PhpCGIServlet has prefer_system_php_exec parameter set to On:


With the above setting you don’t need to populate WEB-INF/cgi/amd64-linux and WEB-INF/cgi/amd64-linux/ext with copies of your php-cgi and php modules.

Check the following URLs (you can replace alias with your domain if it is hosted on our server):<YOURTOMCATHTTPPORT>/JavaBridgeTemplate621<YOURTOMCATHTTPPORT>/JavaBridgeTemplate621/test.php<YOURTOMCATHTTPPORT>/JavaBridgeTemplate621/getjavaproperties.php

NOTE: In case you want to use URLs without port number, make sure your proxy module is set to mod_proxy_ajp. You can check and change it with our custom JVM control panel (JVMCP) where you can also see YOURTOMCATHTTPPORT.

With mod_proxy_ajp set you can also verify the following:

Optional steps:
Rename the webapps/JavaBridgeTemplate621 directory, for example to webapps/drupal, and download your PHP application to this directory. Access the application in your browser e.g., and continue installation as usual.

If you want all your web applications to have the ability to use PHP-Java bridge, install it Tomcat wide. See instructions in PHP-Java bridge FAQ.

If you only want to call Java with a jar contained application from a PHP script see also How to call Java executable from PHP?. See you in next Java hosting article by JVM Host soon!

This entry was posted in Java, Tomcat. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

nine × five =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>