Running php 5.x on windows using tomcat 4.x or 5.x
By Angsuman Chakraborty, Gaea News NetworkSaturday, 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.
Instructions
- Download latest php 5.x zip file.
I used https://www.php.net/get/php-5.0.2-Win32.zip/from/a/mirror . - Download latest Collection of PECL modules. I used https://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:
;extension=php_java.dll - 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" "https://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 https://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.
–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.
Tags: Servlet, Web application
syabac |
Anwar |
June 17, 2010: 3:15 am
THank you very much Angsuman for the tutorial. How ever, as many user, I didn’t success to make it work. can this cause problems? bellow are the lines of error that I get: exception javax.servlet.ServletException: “Servlet.init()” pour la servlet php a généré une exception cause mère java.lang.UnsatisfiedLinkError: no php5servlet in java.library.path ——- java.lang.UnsatisfiedLinkError: send |
manoj |
April 22, 2010: 4:09 am
thanx for such a nice post. |
Smriti |
December 12, 2009: 4:10 am
hello sir, |
Lord Bhima |
September 3, 2009: 3:44 pm
hey Mr.Angshuman |
August 30, 2009: 12:22 am
Great posting, I have been stuck trying to get PHP to run on Tomcat. Thanks for sharing. |
Addy |
August 29, 2009: 6:33 pm
Thanks Buddy Thanks a lot !! |
srikanth T |
July 14, 2009: 11:37 am
Hi, I generated .Jrxml file from iReport.When am i calling .Jrxml file from php application at compilation it is generating a PDF file without data(i,e displaying an empty PDF file).please find the this bug,why it is displaying like that. Thanks in advance Thanks®ards Srikanth T |
kazi |
June 23, 2009: 12:40 pm
But whats Next!!!..After doing all these and integrating with mysql tomcat performance is becomming slow.php to tomcat web server request response performance is significantly poor. Any one?????? |
kazi |
June 17, 2009: 8:21 pm
I can not leave from this site without saying that this is a very useful tutorial. One thing for those who https://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/jar.html this took me around a hour to figure out then for me it was working. |
zahra |
June 8, 2009: 2:07 pm
hi zahra |
Sunil |
May 26, 2009: 12:25 pm
I have following problem after trying above steps. java.lang.UnsatisfiedLinkError: C:\Program Files\Java\jdk1.5.0_16\jre\bin\php5servlet.dll: Can’t load this .dll (machine code=0×501) on a IA 32-bit platform Please try to help resolve this issue… |
Fearil |
May 13, 2009: 5:24 pm
Ok, it work, finally….”php5servlet.dll”, “php5tw.dll” and “msjava.dll” must be in C:\widows\system32\ . But now i want use php mssql list of commad. |
Fearil |
May 6, 2009: 10:02 am
Sorry, i follow all step and erased th blank line in proprety file, but it still not work. java.lang.UnsatisfiedLinkError: no php5servlet.dll in java.library.path someone can help me???? thanks |
Subash |
May 2, 2009: 10:42 am
Hi Everyone, Thank you all for lots of troubleshooting tips ! Finally, i have a tomcat Server integrated with php after two days of hardwork. All the tips that is mentioned does work. I am telling this with confidence as i have faced all the problems that each of you had faced. Hmmmmm…Now i will relax Thanks again |
TheBlueSky |
April 28, 2009: 10:32 am
Thanks for the helpful HOW-TO. I had some hard time finding the files php5servlet.dll and php5srvlt.jar, but thanks to Google, everything was put in place However, when I browse to https://localhost:8080/php/index.php (the URL in my case) I get HTTP 404 error saying: Any help or hint is really appreciated. Thanks |
Shah al |
March 14, 2009: 11:59 pm
I was trying this too. Tried taking all the latest libraries and follow the tutorial. But it did not work. Unsatisfied link error. For some reason pecl-5.2.6 does not have the mentioned files or jar. so reverted back to pecl-5.2.5 and it had the necessary dll and jar. However it did not work until all the dll’s were moved to C:\windows\system32. After moving the dlls there everything worked. - shah al |
January 21, 2009: 10:35 pm
[...] Yesterday I tried to instal PHP on Tomcat running on Windows. I used this tutorial as my guide: https://blog.taragana.com/index.php/a…mcat-4x-or-5x/ First I did everything like it is said in tutorial and I got an error: net.php.servlet.send(Native [...] |
Ashok |
November 20, 2008: 7:33 am
Hi, I downloaded latest versions - pecl-5.2.6-Win32 and php-5.2.6-Win32. But I could not find php5srvlt.jar any where, even in pecl-5.2.6-Win32 as explained. Where do i get this jar file? Thanks in advance. |
Ashok |
August 22, 2008: 7:23 am
hi, ashok |
June 25, 2006: 8:59 am
I hope you understand it is very hard to keep supporting this post so long down the line. The post was written in 2004. I am closing the post for further comments. Please read the comments above. All types of problems have been addressed and solved at some time or other. If you still need help please contact me directly using the form / email provided in the top-left corner of this page. Best, |
Dave Raasch |
June 24, 2006: 4:48 pm
Geez, this is killing me! I can’t run a PHP application (clicking from screen to screen) for more than maybe 5 minutes! Tomcat keeps crashing! See my previous post (# 192). Any recommendations? -= Dave =- |
julia mainstreem |
June 23, 2006: 6:31 am
Ok, i made it like the guide above, read all the hints, but i get only: I use |
Lalit Mehta |
June 21, 2006: 3:06 pm
I installed PHP 4 on Tomcat 5 using java 5 on Linux platform. It compiled correctly but when I run php page, it shows up in catalina.out instead of the browser. Any ideas? |
Peter |
June 20, 2006: 6:39 pm
and java servlets are all working fine… but i need to have php5 => php-java-bridge.sf.net |
Marcel |
June 18, 2006: 9:50 am
Hi all, Just a quick post to pose my problem. I have followed the instructions and used information from previous posts to solve most of the problems that i have come up against but now i am stumped. when i call my test.php file, it flashes up then my tomcat server dies and i have to restart it. other JSP and beans and java servlets are all working fine… but i need to have php5 and this is my last stumbling block. Once again thanks to you Angsuman as well as all the others who have contributed to this thread. |
Dave Raasch |
June 16, 2006: 12:43 pm
I have installed php 5.1.4 along with the pcl version 5.1.4. Tomcat version is 5.5.7. This is on a machine running Windows 2000. I have a php script that basically refreshes itself / executes again every 5 minutes. And while this script worked just fine on its old server (running IIS)… and seems to work fine most of the time now in this new environment, I’m finding that Tomcat will crash / won’t stay up for more than an hour. This means I have to manually go back and restart my script. I located the hs_err_pid*.log files that occur with each crash. They commonly start with: # So, I’m guessing this is indicating that php5ts.dll is where we’re encountering some sort of problem that causes the crash. ? It seems like several people here have mentioned this problem… but it’s unclear as to whether they can run PHP scripts for a while before it happens. Is anybody else having this happen after PHP is running scripts fine for a while? Does anybody know a solution to this? Thank you, Dave |
Dave Raasch |
June 14, 2006: 4:30 pm
I know that the line in both reflect.properties and servlet.properties should not have a space in it… but a line break / carriage return is okay, right? Sorry to be such a noob. -= Dave =- |
Domai Murah