Running php 5.x on windows using tomcat 4.x or 5.xBy Angsuman Chakraborty, Gaea News Network
Saturday, December 11, 2004
What it solves:
- Using php 5.x on Tomcat 4.x or 5.x
- Enabling php only in one web application, instead of globally.
The simplest possible configuration is described. The descriptions are terse assuming your intelligence.
We will assume php will be installed in c:\ drive. Substitute with drive letter of your choice.
- Download latest php 5.x zip file.
I used http://www.php.net/get/php-5.0.2-Win32.zip/from/a/mirror .
- Download latest Collection of PECL modules. I used http://www.php.net/get/pecl-5.0.2-Win32.zip/from/a/mirror .
- Unzip php 5.x zip file anywhere, normally c:\php
- Copy php.ini-dist, in c:\php, as php.ini
- Uncomment the line (remove semi-colon at the beginning) in php.ini:
- Extract php5servlet.dll from pecl zip file to c:\php (Uncheck "Use Folder Names" in WinZip).
Ensure that the file is actually present in c:\php
- Install Tomcat and create a directory under webapps. Lets say it is named fun.
- Create WEB-INF directory under fun
- Create lib directory under WEB-INF
- Create web.xml under WEB-INF with the following contents:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <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> </servlet-mapping> </web-app>
- Extract php5srvlt.jar and extract/unjar (jar xvf …) it under c:\
- Modify both the files reflect.properties and servlet.properties to change the line library=phpsrvlt to library=php5servlet and save them. This indicates the file name of the dll file which is loaded by the Java application to serve the requests. In my version the name of the dll was php5servlet.dll. Your mileage may vary. This has no connection with the name of the jar file which can be anything.
- Re-create the jar file
- Copy the jar file to WEB-INF\lib directory created earlier
- Add c:\php to your System or User Path in Windows enironment (Hint: Right-click and select Properties from My Computer)
- Create a file test.php under fun with the following code:
<?php phpinfo(); ?>
- Start Tomcat (Go to [Tomcat installation directory]\bin and type Tomcat).
- Open your browser and go to http://localhost:8080/fun/test.php
- Ensure that there are no errors displayed. Instead you get an informative screen with php version information and whole lot of details
Let me know if this document is helpful to you.
Update: Made minor revision to highlight some key elements.
Solutions to common problems by users:
Whoever is getting this error “java.lang.UnsatisfiedLinkError: no php5servlet in java.library.path”. Please check the two properties file, whether there are any blank spaces. I was stuck in this problem for 2 days. There should be only one line, and no blank spaces. Check it now!!!. This is where the problem is lying.
The versions of php and pecl must be the same.
You might want to add a reboot step at the end of your instructions. It would eliminate a lot of the problems with the unsatisfied link errors.
– Chuck Rosendahl
If you find this tutorial useful, please consider donating and enjoy the pleasure of giving.
Tags: Servlet, Web application