Tomcat Wiki
Using PHP With Tomcat
PHP version 5 is not currently supported as it does not include the necessary servlet code.
Prerequisites
Patch for PHP configure Script
Prior to version 2.4 of Servlet Specification, the name of the servlet jar file was servlet.jar. In version 2.4 of the Servlet Specification, this name was changed to servlet-api.jar. Tomcat 4 uses the name servlet.jar, whereas Tomcat 5 and later uses servlet-api.jar. This causes problems with PHP's configure script.
--- configure.org 2004-04-07 11:20:24.000000000 +0200
+++ configure 2004-04-07 11:22:50.000000000 +0200
if test "$withval" = "yes"; then
SERVLET_CLASSPATH=.
else
+ if test -f $withval/common/lib/servlet-api.jar; then
+ SERVLET_CLASSPATH=$withval/common/lib/servlet-api.jar
+ fi
+
if test -f $withval/lib/servlet.jar; then
SERVLET_CLASSPATH=$withval/lib/servlet.jar
fi
Patch for sapi/servlet/servlet.java
--- servlet.java.orig 2005-09-26 22:25:55.000000000 -0400
+++ servlet.java 2005-09-26 22:26:11.000000000 -0400
@@ -63,12 +63,12 @@
if (!request.getMethod().equals("POST")) {
result = request.getQueryString();
} else {
- Enumeration enum = request.getParameterNames();
+ Enumeration xenum = request.getParameterNames();
String concat = "";
result = "";
- while (enum.hasMoreElements()) {
- String name = (String)enum.nextElement();
+ while (xenum.hasMoreElements()) {
+ String name = (String)xenum.nextElement();
String value = request.getParameter(name);
PHP Installation
./configure --with-servlet=$TOMCAT_HOME --with-java=$JAVA_HOME
Modify your LD_LIBRARY_PATH to include the dynamic library produced in the first step above:LD_LIBRARY_PATH=$PHP_HOME/libs
export LD_LIBRARY_PATHAs an option, you can put libphp4.so someplace where java is already looking, any place in System.getProperty("java.library.path"), such as any of:
/usr/lib/jdk1.5.0_04/jre/lib/i386/client:/usr/lib/jdk1.5.0_04/jre/lib/i386:/usr/lib/jdk1.5.0_04/jre/../lib/i386Fedora Core 1 Issues with Tomcat 5.5.9, PHP 4.3.11 and jdk1.5.0_03
If make returns an error regarding "enum" while trying to build phpsrvlt.jar, you'll need to edit $PHP_HOME/sapi/servlet/servlet.java and replace enum with xenum.
Start Tomcat
Testing
<servlet><servlet-name>php</servlet-name>
<servlet-class>net.php.servlet</servlet-class>
</servlet>
<servlet>
<servlet-name>php-formatter</servlet-name>
<servlet-class>net.php.formatter</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>php</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>php-formatter</servlet-name>
<url-pattern>*.phps</url-pattern>
Create a file named test.php in the docBase directory of your webapp.
If everything is working as it should, you will see an informational status page produced by PHP.
UsingPhp (last edited 2012-04-23 02:26:20 by ChuckCaldarale)