Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Using PHP With Tomcat

This page describes how to use PHP (v4) with Tomcat (v4 or later). The contents were originally written and sent to the tomcat-dev list by Jean-Frederic Clere (on his vacation, no less (wink) ) and Henri Gomez.*

...

  • 0. Prerequisites:
    ** Download PHP (this tutorial was done with PHP 4.3.5)
    ** Download Tomcat (this tutorial was done with Tomcat 5.0.19)
    ** Define $JAVA_HOME for your JDK installation
    ** Define $TOMCAT_HOME for your tomcat installation
    ** Define $PHP_HOME for your PHP installation

...

  • 1. Configure PHP Installation:
    ./configure --with-servlet=$TOMCAT_HOME --with-java=$JAVA_HOME

A jarfile and dynamic library are produced:

  • sapi/servlet/phpsrvlt.jar
  • libs/libphp4.so

...

  • 2. Copy jar to your webapp's or tomcat's common class repository:
    cp $PHP_HOME/sapi/servlet/phpsrvlt.jar $TOMCAT_HOME/common/lib

...

  • 3. Declare PHP servlet and servlet-mapping in your or tomcat's common web.xml:
    Copy from $PHP_HOME/sapi/servlet/web.xml servlet and servlet-mapping and paste
    into $TOMCAT_HOME/conf/web.xml.

...

  • 4. Modify your LD_LIBRARY_PATH to include the dynamic library produced in step 1 above:
    LD_LIBRARY_PATH=$PHP_HOME/libs
    export LD_LIBRARY_PATH

...

  • 5. Start tomcat:
    $TOMCAT_HOME/bin/startup.sh.

...

Testing:

  1. Create a file named test.php in the docBase directory of your webapp.

...