Want to run PHP and access Java? Here's how to do it on Windows XP using Apace and Apache Tomcat. Apache Tomcat is a Servlet container developed at the Apache Software Foundation (ASF). Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems, and provides a "pure Java" HTTP web server environment for Java code to run. Tomcat should not be confused with the Apache web server, which is a C implementation of a HTTP web server; these two HTTP web servers are not bundled together. Apache Tomcat includes tools for configuration and management, but can also be configured by editing configuration files that are normally XML-formatted.
Try it using XAMPP
Although the tutorial show you how to do things by installing Apache Tomcat, this may not be ideal or what most want to do. One of the things that stopped me from digging into Java web development is the fact that setting up an environment on Windows is just as hard as finding a cheap Java web hosting company. That and the fact that I like to be able to turn my development environments on and off. But now thanks to apachefriends.org half of my problem is solved. They have released an Apache Windows XAMPPpackage with an easy to install Apache Tomcat add-on. I have been waiting a long time for this to happen. This event should make things even easier for beginners.
Select "Full" from the dropdown, and then click Next >.
Click Next >. (in my case, C:\Program Files\Apache Group\Tomcat 5.5)
Enter an admin password, and then click Next >.
Verify the J2SE 5.0 JRE installation path is correct, and then click Install. (in my case, C:\Program Files\Java\jre1.5.0_10)
click Finish.
Open http://localhost:8080/ in your web browser. If you see something like the following, you have properly installed Tomcat!
To install PHP as FastCGI, add these lines (from c:\php-java-bridge-3.2.1_j2ee\WEB-INF\web.xml)
to the end of your web.xml file (C:\Program Files\Apache Group\Tomcat 5.5\conf\web.xml):
...
<!-- From c:\php-java-bridge-3.2.1_j2ee\WEB-INF\web.xml -->
<!-- Faces Servlet -->
<servlet>
<servlet-name>PhpFacesServlet</servlet-name>
<servlet-class>php.java.faces.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<!-- PHP Servlet: back-end for Apache or IIS -->
<servlet>
<servlet-name>PhpJavaServlet</servlet-name>
<servlet-class>php.java.servlet.PhpJavaServlet</servlet-class>
<!-- Allow non-local clients. These clients connect to the -->
<!-- back-end using a HTTP tunnel. Default is Off. -->
<!-- Leave this off if your server is connected to the internet. -->
<!--
<init-param>
<param-name>allow_http_tunnel</param-name>
<param-value>On</param-value>
</init-param>
-->
<!-- Default it the java.log_level from the php.ini. -->
<!-- See also the system property php.java.bridge.default_log_level -->
<!--
<init-param>
<param-name>servlet_log_level</param-name>
<param-value>2</param-value>
</init-param>
-->
<load-on-startup>0</load-on-startup>
</servlet>
<!-- PHP CGI servlet: when IIS or Apache are not available -->
<servlet>
<servlet-name>PhpCGIServlet</servlet-name>
<servlet-class>php.java.servlet.PhpCGIServlet</servlet-class>
<!-- Allow us to override the java.hosts, java.servlet and -->
<!-- java.socketname settings from your php.ini so that we can -->
<!-- use the current VM (see X_JAVABRIDGE_OVERRIDE_HOSTS). -->
<!-- Default is On. -->
<!--
<init-param>
<param-name>override_hosts</param-name>
<param-value>Off</param-value>
</init-param>
-->
<!-- Your php binary. Default is /usr/bin/php-cgi or -->
<!-- c:/php/php-cgi.exe -->
<!--
<init-param>
<param-name>php_exec</param-name>
<param-value>php-cgi</param-value>
</init-param>
-->
<!-- The number of concurrent cgi requests -->
<!-- Note that this value should be 1/2 of the servlet engine's -->
<!-- thread pool size because each PhpCGIServlet instance also -->
<!-- consumes one PhpJavaServlet instance -->
<!--
<init-param>
<param-name>max_requests</param-name>
<param-value>50</param-value>
</init-param>
-->
<!-- Use the fast cgi interface instead of cgi when running -->
<!-- php as a CGI sub component (when php is not installed as an -->
<!-- Apache or IIS module). Values: Off, On, Autostart. -->
<!-- Default is Autostart. -->
<!--
<init-param>
<param-name>use_fast_cgi</param-name>
<param-value>Off</param-value>
</init-param>
-->
<!-- Share the FastCGI pool from the JavaBridge PhpCGIServlet with -->
<!-- the GlobalPhpCGIServlet used by all other web apps. -->
<!-- Set this to On in both, the JavaBridge/WEB-INF/web.xml and -->
<!-- in the global conf/web.xml. -->
<!-- Default is Off. -->
<!-- See http://php-java-bridge.sf.net#global-servlet for details. -->
<init-param>
<param-name>shared_fast_cgi_pool</param-name>
<param-value>On</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>PhpFacesServlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!-- PHP Servlet Mapping -->
<servlet-mapping>
<servlet-name>PhpJavaServlet</servlet-name>
<url-pattern>*.phpjavabridge</url-pattern>
</servlet-mapping>
<!-- PHP CGI Servlet Mapping -->
<servlet-mapping>
<servlet-name>PhpCGIServlet</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
<!-- Welcome files -->
<welcome-file-list>
<welcome-file>index.php</welcome-file>
</welcome-file-list>
...
</web-app>
Copy JavaBridge.jar and php-servlet.jar from C:\php-java-bridge-3.2.1_j2ee\WEB-INF\lib to C:\Program Files\Apache Group\Tomcat 5.5\shared\lib.
PHP 5 & Java Bridge
You may use some sort of tools to unzip the php-java-bridge_3.2.1_j2ee.zip
file. I used ALZip.
Copy JavaBridge.jar from the JavaBridge.war to C:\PHP\ext.
Copy java-x86-windows.dll from the JavaBridge.war to C:\PHP\ext.
Rename java-x86-windows.dll (from C:\PHP\ext) to php_java.dll
To set up a valid configuration file for PHP, make a copy of
php.ini-recommended then rename it to the php.ini.
Edit the php.ini so that the
"extension_dir" points to your PHP 5 extension directory.