Monday, December 24, 2012

Running php 5.x on windows using tomcat 4.x or 5.x

Running php 5.x on windows using tomcat 4.x or 5.x

By Angsuman Chakraborty, Gaea News Network
Saturday, December 11, 2004

What it solves:
  1. Using php 5.x on Tomcat 4.x or 5.x
  2. 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.
Instructions
  1. Download latest php 5.x zip file.
    I used http://www.php.net/get/php-5.0.2-Win32.zip/from/a/mirror .
  2. Download latest Collection of PECL modules. I used http://www.php.net/get/pecl-5.0.2-Win32.zip/from/a/mirror .
  3. Unzip php 5.x zip file anywhere, normally c:\php
  4. Copy php.ini-dist, in c:\php, as php.ini
  5. Uncomment the line (remove semi-colon at the beginning) in php.ini:
    ;extension=php_java.dll
  6. 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
  7. Install Tomcat and create a directory under webapps. Lets say it is named fun.
  8. Create WEB-INF directory under fun
  9. Create lib directory under WEB-INF
  10. 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>
       
  11. Extract php5srvlt.jar and extract/unjar (jar xvf …) it under c:\
  12. 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.
  13. Re-create the jar file
  14. Copy the jar file to WEB-INF\lib directory created earlier
  15. Add c:\php to your System or User Path in Windows enironment (Hint: Right-click and select Properties from My Computer)
  16. Create a file test.php under fun with the following code:
    <?php phpinfo(); ?>
  17. Start Tomcat (Go to [Tomcat installation directory]\bin and type Tomcat).
  18. Open your browser and go to http://localhost:8080/fun/test.php
  19. 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.
–Arundhati
The versions of php and pecl must be the same.
–Mirek Mocek
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
Note:
If you find this tutorial useful, please consider donating and enjoy the pleasure of giving.

0 comments:

Post a Comment

 
Design by I Love PHP