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 php-java-bridge_6.2.1_documentation.zip 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:
<?php require_once("java/Java.inc"); 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:
<servlet> <servlet-name>PhpCGIServlet</servlet-name> <servlet-class>php.java.servlet.fastcgi.FastCGIServlet</servlet-class> <load-on-startup>0</load-on-startup> <init-param> <param-name>prefer_system_php_exec</param-name> <param-value>On</param-value> </init-param> <init-param> <param-name>php_include_java</param-name> <param-value>Off</param-value> </init-param> </servlet>
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 username.jvmhost.net alias with your domain if it is hosted on our server):
http://username.jvmhost.net:<YOURTOMCATHTTPPORT>/JavaBridgeTemplate621 http://username.jvmhost.net:<YOURTOMCATHTTPPORT>/JavaBridgeTemplate621/test.php http://username.jvmhost.net:<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:
http://username.jvmhost.net/JavaBridgeTemplate621 http://username.jvmhost.net/JavaBridgeTemplate621/test.php http://username.jvmhost.net/JavaBridgeTemplate621/getjavaproperties.php
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. http://username.jvmhost.net/drupal, 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!