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 https://www.php.net/get/php-5.0.2-Win32.zip/from/a/mirror .
  2. Download latest Collection of PECL modules. I used https://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"
      "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>
    			
  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 https://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.

Discussion
August 9, 2010: 10:23 pm

how to create web.xml ??


syabac
July 13, 2010: 10:55 pm

i tried to install php within tomcat, but it was failed.. please..


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.
The only thing I didn’t do exactly as you described is the unjar the jar. I had to do it with winzip. I just changed the extension .jar to .zip.. I worked on the files as you said, and than I rezipped the file and finally changed the .zip to .jar again.

can this cause problems? bellow are the lines of error that I get:
——–
The first time that I lunch tomcat, I get all these errors :

exception

javax.servlet.ServletException: “Servlet.init()” pour la servlet php a généré une exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)

cause mère

java.lang.UnsatisfiedLinkError: no php5servlet in java.library.path
java.lang.ClassLoader.loadLibrary(Unknown Source)
java.lang.Runtime.loadLibrary0(Unknown Source)
java.lang.System.loadLibrary(Unknown Source)
net.php.reflect.loadLibrary(reflect.java:34)
net.php.reflect.(reflect.java:29)
net.php.servlet.init(servlet.java:157)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)

——-
After that, every time I reload the page, I get the following :

java.lang.UnsatisfiedLinkError: send
net.php.servlet.send(Native Method)
net.php.servlet.service(servlet.java:190)
net.php.servlet.service(servlet.java:214)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


manoj
April 22, 2010: 4:09 am

thanx for such a nice post.
i completed all steps with winxp, tomcat 6, php 5.3.2 and pecl 5.2.6. still giving below error. changed jar - property files (no spaces), restarted pc also. no luck.
=======
Apr 22, 2010 2:16:06 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet php threw exception
java.lang.UnsatisfiedLinkError: net.php.servlet.send(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Z)V
at net.php.servlet.send(Native Method)
at net.php.servlet.service(servlet.java:190)
at net.php.servlet.service(servlet.java:214)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527)
at java.lang.Thread.run(Unknown Source)


Smriti
December 12, 2009: 4:10 am

hello sir,
i m kinda novice and trying to learn php on my own by online tutorials.
buttttt even after following ur steps word by word, my website isnt even starting !
may sound dumb ………
but plzzzz help me.


Lord Bhima
September 3, 2009: 3:44 pm

hey Mr.Angshuman
i have done all the steps but when i use chrome got a blank page and when use internet explorer got HTTP-404
file not found error….
what can i do?

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 :)
it works
get the link for downloading php5servlet.jar here
https://the-double-0-project.net/blog/?p=49

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&regards

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
try this tutorial please be careful about the jar and unjar file.Use this link as a pathway

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.
Best regards


zahra
June 8, 2009: 2:07 pm

hi
I have Tomcat 5 running on my Windows XP. PHP_HOME is pointing to c:/program files/PHP, I have gone through these steps, but when re-creating the jar file, the size of the new file, gets reduced from 16k to 9k!! and when I want to get a .php page, it has the 404 error!! Tomcat is working fine with .jsp files. would you please please please help me in finding the fault. its really important for me to get this working.

zahra


Sunil
May 26, 2009: 12:25 pm

I have following problem after trying above steps.
I am using php5 and tomcat 5.x in windowx xp…

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
java.lang.ClassLoader$NativeLibrary.load(Native Method)
java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1668)
java.lang.Runtime.loadLibrary0(Runtime.java:822)
java.lang.System.loadLibrary(System.java:993)
net.php.reflect.loadLibrary(reflect.java:34)
net.php.reflect.(reflect.java:29)
net.php.servlet.init(servlet.java:157)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:595)

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.
I have modified the php.ini fr load php_mssql.dll
but using mssql_connect(’host’,'user’,'psw’); doesn’t work “Call to undefined function mssql_connect()”
Help me please.


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.
The error is:

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 !
Special thanks to angsuman..

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:
message: Servlet php in not available
description: The requested resource (Servlet php is not available) in not available.

Any help or hint is really appreciated.

Thanks

March 16, 2009: 10:28 am

Thanks for sharing.


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


Ashok
August 22, 2008: 7:23 am

hi,
how can i cinfigure php 5.2.6 in apache tomcat 5.5 in linux , i need the complete help ,from php installation

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,
Angsuman


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:
java.lang.UnsatisfiedLinkError: no php_java in java.library.path”
when i call the test.php ;(

I use
apache-tomcat-5.5.17
pecl-5.1.4-Win32
php-5.1.4-Win32
WinXP SP2


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.
Firstly, Angsuman thanks for your post and ongoing support far beyond the call.

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:

#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0×486b91e4, pid=3268, tid=3692
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_01-b08 mixed mode)
# Problematic frame:
# C [php5ts.dll+0x91e4]
#

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 =-

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :