Contact: Web / Voice / Email / Tips
Simple Thoughts Blog - Java and Web Technologies

Simple solutions for complex problems.

 

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

December 11th, 2004 by Angsuman Chakraborty

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.


Filed under Headline News, How To, Java Software, PHP, Technology, Web, Web Services | | RSS 2.0 | Trackback this Article | Email this Article

You may also like to read

»JSP / Servlet - PHP Integration Options
»Eclipse 3.1 + Tomcat 5.5 Integration Solution
»Tomcat 5.5 with Apache 2.0 Integration in 5 Simple Steps
»What Java Needs Most To Be The Preferred Web 2.0 Language
»Mystery of Vanishing Sysdeo Tomcat Plugin for Eclipse
»Running cgi-bin on Tomcat: Simple steps & gotchas
»J2EE Performance Improvement 3X on Linux
»How to run javac 1.5 (or beyond) compiler for JSP compilation in Tomcat 5.5 with generics enabled (and other Java 1.5 only features like autoboxing)
»How To Resolve Tomcat - Openfire Port Conflict
»How To: Triple Monitor Setup With Dual Monitor & Laptop (Linux & Windows)
»Microsoft Windows Genuine Advantage Scales Back; Rumors of Disabling Pirated Copies
»How To Fool Windows Genuine Advantage in 15 Minutes
»Microsoft Clamps Down on Windows Piracy
»Other causes of failing DNS lookup on Windows
»How to unload Java Class

The comments are currently closed for this post.

196 Responses to “Running php 5.x on windows using tomcat 4.x or 5.x”

  1. analogueboy Says:

    I tried this b4 (http://analogueboy.blogspot.com/#106959689637832829) but it wasn’t very reliable. I tried to run phpbb under tomcat and it repeated failed. Have you found the process to be more reliable under php5?

  2. Angsuman Chakraborty Says:

    The system was stable so long you didn’t have to reload the web application. In the given installation scenario the jar which loaded the native dll is loaded from the web application context. So re-loading web application causes problem. It is better to restart Tomcat. However I presume that will be gone if the jar is moved to common/lib.

  3. Prakash Says:

    i m getting this error

    javax.servlet.ServletException: Servlet execution threw an exception

    root cause

    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:802)

  4. bill Says:

    # Extract php5srvlt.jar and extract/unjar (jar xvf …) it under c:\
    WHAT DO YOU MEAN BY THIS LIGNE
    # Modify both the files reflect.properties and servlet.properties to change the line library=phpsrvlt to library=php5servlet and save them

    HERE I CAN’T FIND REFLET AND SERVLET.PROPERTIES?
    # Re-create the jar file
    HERE ALSO WITCH FILE
    # Copy the jar file to WEB-INF\lib directory created earlier
    # Add c:\php to your System/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

    I FIND THIS IN INTERNET = IT DOESN’
    T WORK

    the php5 version of phpsrvlt.jar is not working correctly because of a
    mistake in
    net\php\reflect.properties
    and
    net\php\servlet.properties

    there’s one space after the library name that should be stripped.

    after doing this i’ve no problem using php5 out of an java appserver.

    mfg,
    28 Oct 1:30pm CEST] MerlinDMC at t-online dot de

    CAN YOU HELP ME PLEASE

  5. bill Says:

    Etat HTTP 500 -

    ——————————————————————————–

    type Rapport d’exception

    message

    description Le serveur a rencontré une erreur interne () qui l’a empêché de satisfaire la requête.

    exception

    javax.servlet.ServletException: L’exécution de la servlet a lancé une exception

    cause mère

    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:853)

    note La trace complète de la cause mère de cette erreur est disponible dans les fichiers journaux de Apache Tomcat/5.5.6.

  6. Angsuman Chakraborty Says:

    I don’t understand Spanish. However I believe the content of the two comments above are the same - UnsatisfiedLinkError.

    As the jar file is placed under web-inf/lib directory realoding the web container causes the dll to be reloaded again which fails.
    The simplest solution is to restart the server whenever there is a need to restart the web conatiner. However to eliminate the problem totally you can place the jar under common/lib directory. That way it is loaded the tomcat classloader and is not restarted when the web container is restarted.

    Let me know if that helps.

  7. Angsuman Chakraborty Says:

    Bill> the php5 version of phpsrvlt.jar is not working correctly because of a mistake in net\php\reflect.properties and net\php\servlet.properties. There’s one space after the library name that should be stripped. After doing this i’ve no problem using php5 out of an java appserver.

    The problem has been addressed in steps 11-13 above (quoted below for convenience):
    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
    13. Re-create the jar file

  8. Lukas Brozovsky Says:

    Hi. I followed all the steps with no problem. The only difference was at step 11 (”Extract php5srvlt.jar and extract/unjar (jar xvf …) it under c:”). Extract from where? I suppose it’s located in PECL zip file. There was only “phpsrvlt.jar” so I used that instead. Everything else was fine.
    Now step 19: on the first page request from the browser I get following error:

    java.lang.IllegalAccessError: tried to access method net.php.reflect.loadLibrary(Ljava/lang/String;)V from class net.php.servlet
    net.php.servlet.init(servlet.java:157)
    [snipped]
    …every other page request results in this error:

    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:802)

    I’m pretty sure I did all your steps, so where could be the problem?! I’m using Tomcat 5.5.4 and PHP 5.0.3…
    Thanks in advance for your help.

  9. Angsuman Chakraborty Says:

    Lukas> The only difference was at step 11 (”Extract php5srvlt.jar and extract/unjar (jar xvf …) it under c:”). Extract from where? I suppose it’s located in PECL zip file. There was only “phpsrvlt.jar” so I used that instead. Everything else was fine.

    Angsuman> I meant extract the contents of phpsrvlt.jar. The idea is to change the content of the two properties file within the jar file. And yes you will get the jar file in pecl.zip.

    Lukas>Now step 19: on the first page request from the browser I get following error

    Angsuman> Please make the changes and let me know if you still face the problem.

  10. Brian Says:

    Hi. I’m using Tomcat 5.5.4 with PHP 5.03. I’ve followed all the instuctions above and got to step 19. When I go to http://localhost:8080/fun/test.php I get a blank screen. When I look at the source, it contains < ?php phpinfo(); ?> It appears that Tomcat is loading the test.php file but the php script is not running. I’ve tried this with and without the extra spaces in reflect.properties and servlet.properties and get the same behavior. Thanks for your help!

  11. Brian Says:

    Hi. That last message was supposed to say “it contains phpinfo();” but the website didn’t like the LT/GT ?

  12. Lukas Brozovsky Says:

    Finally got it working! The problem was in my classpath setup. I got two different php_java.jar files accessible through classpath and Java was all confused with it (that’s why I was still getting this java.lang.IllegalAccessError)…
    Now I’m wondering if there’s a way to call Java code within the servlet’s JVM from the actual PHP code. To be more specific: I need to create Java singleton in PHP code and share this singleton within all server PHP-requests (I tried PHP - Java integration using PHP object Java [ie. < ?php $i = new Java('java.lang.Integer'); ?>] but PHP interpretter was starting extra JVM for each single page it interpretted). Any ideas? Thanks…

  13. Angsuman Chakraborty Says:

    Lukas> Now I’m wondering if there’s a way to call Java code within the servlet’s JVM from the actual PHP code. To be more specific: I need to create Java singleton in PHP code and share this singleton within all server PHP-requests (I tried PHP - Java integration using PHP object Java [ie. ] but PHP interpretter was starting extra JVM for each single page it interpretted). Any ideas? Thanks…

    There is a simple way and there is a complicated way :)
    The simple way would be to write a jsp page which contains the desired code and load the page from php code.

  14. Angsuman Chakraborty Says:

    Brian> Hi. I’m using Tomcat 5.5.4 with PHP 5.03. I’ve followed all the instuctions above and got to step 19. When I go to http://localhost:8080/fun/test.php I get a blank screen. When I look at the source, it contains It appears that Tomcat is loading the test.php file but the php script is not running. I’ve tried this with and without the extra spaces in reflect.properties and servlet.properties and get the same behavior. Thanks for your help!

    Brian,
    I think you missed step 10. That creates the mapping between .php file and the servlet.

    Please check and let me know.

  15. Brian Says:

    Angsuman> I tried repeating step 10 again, assuming I made a mistake, but was still unable to get this to work. Is the php5srvlt.jar supposed to be in the C:/php directory as well, or just the WEB-INF/lib? When I recreate the jar, does it suffice to edit the reflect.properties and servlet.properties files and overwrite the files in the jar or do I need to use the java command to rebuild the jar???

    This is what my directory structure looks like:
    webapps/fun/
    test.php
    WEB-INF/
    /lib
    web.xml
    php5srvlt.jar

    Thanks again!

  16. Angsuman Chakraborty Says:

    Brian> I tried repeating step 10 again, assuming I made a mistake, but was still unable to get this to work.

    Angsuman> Any errors in tomcat log files?

    Brian> Is the php5srvlt.jar supposed to be in the C:/php directory as well, or just the WEB-INF/lib?

    Angsuman> Just WEB-INF/lib should be fine.

    Brian> When I recreate the jar, does it suffice to edit the reflect.properties and servlet.properties files and overwrite the files in the jar or do I need to use the java command to rebuild the jar???

    Angsuman> I am not sure I understand. You need to unjar the files, modify them and then rebuild the jar and deploy the new jar file. Verify it by checking that the files have actually been changed and that the path information of the files is identical to the original. The steps given, if followed to the dot should ensure that.

    Brian> This is what my directory structure looks like:
    webapps/fun/
    test.php
    WEB-INF/
    /lib
    web.xml
    php5srvlt.jar

    Angsuman> The directory structure is not clear from this comment. The php file should be under fun. WEB-INF/web.xml, WEB-INF/lib/*.jar should be the normal order of files.

    Specifically web.xml should be under WEB-INF directory and not under lib.

    Hope that clarifies…

  17. Sachin Says:

    Well, I have a weird problem. Everything is set up, but I get this exception about gibberish:
    java.io.IOException: °?ü°?ü¸?ü¤Cüü>–
    at net.php.servlet.send(Native Method)
    at net.php.servlet.service(servlet.java:190)
    [snipped]

    Do let me know if you have any information on this.
    Thanks,
    Sachin

  18. Sachin Says:

    Sorry for a hasty post previously, that problem is solved. I do have another problem, but I haven’t started working on solving it yet. Its about a fairly complex php page not displaying properly. Will post more on that in case I can’t solve it. Once again, sorry for the big (and useless) post above.
    Thanks,
    Sachin

  19. Angsuman Chakraborty Says:

    No problem! Let me know how it gies Sachin. Do share if you have found something new.

  20. Brian Says:

    I am receiving a similar error to what Sachin was getting and was wondering what the solution to that was? The first time I try to lead the page I am getting this error:

    javax.servlet.ServletException: Servlet.init() for servlet php threw exception
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    [snipped]

    root cause

    java.lang.UnsatisfiedLinkError: no php5srvlt in java.library.path
    java.lang.ClassLoader.loadLibrary(Unknown Source)
    [snipped]
    When I reload the page I get this error:

    javax.servlet.ServletException: Servlet execution threw an exception

    root cause

    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:802)
    Thanks for the help!

  21. Angsuman Chakraborty Says:

    Brian,

    Is php5srvlt.jar file under WEB-INF\lib directory?

    Please restart tomcat and let me know if the problem persists.

    Angsuman

  22. Angsuman Chakraborty Says:

    BTW: Made a small update to the post to clarify that web.xml should be placed under WEB-INF directory. I previously assumed everyone knows that due to previous experience with servlets.

  23. Nikhil Says:

    sorry…. nooobie here, How to Rebuild jar file ?

  24. Nikhil Says:

    ok to unjar -> “jar xfv phpsrvlt.jar”

    to Recreate the jar file -> “jar cvf php5srvlt.jar net/php/*.*

    done this and pasted the newly created jar file into c:\php and fun\WEB-INF

    but apparently my Tomcat root seems to be the webapps\ROOT folder, n not just Webapps.. so I pasted my ‘fun’ inside this ROOT folder…

    k but still gettin a blank page :(

  25. Nikhil Says:

    oh.. and one more thing… my root already seems to have a WEB-INF with a lib n web.xml within it…
    this doesn affect anything rite ? :)

  26. Nikhil Says:

    HTTP Status 500 -

    ——————————————————————————–

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    javax.servlet.ServletException: Servlet.init() for servlet php threw exception
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    [snipped]

    root cause

    java.lang.UnsatisfiedLinkError: no php5servlet in java.library.path
    java.lang.ClassLoader.loadLibrary(Unknown Source)
    [snipped]

    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.4 logs.

    ——————————————————————————–

    Apache Tomcat/5.5.4

  27. Nikhil Says:

    hmmm “webapps” seems to be the root now… haha

    and the ‘php5srvlt.jar’ is inside the tomcat - ‘C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\run\WEB-INF\lib’ folder..

    but still gettin the same error as Brain…. as stated in the above previous post..

  28. Angsuman Chakraborty Says:

    Nikhli,
    Please read the tomcat documentation.
    To create a web app you can either use ROOT (not advisable) or create a directory with any name and create certain directories like WEB-INF under it. Also create a web.xml under WEB-INF.

  29. Nikhil Says:

    Hi angsuman,

    yup, did that, but still the error :(

  30. Jason Says:

    hi Nikhil, all –

    I have the answer to your problem, which I was encountering also. Just got this working after about an hour of banging on it.

    The problem is that the reflect.properties and servlet.properties files that we are modifying inside the jar actually point to the DLL file….so the line MUST read
    library=php5servlet

    Because the instructions above are unclear, we were all confused about the difference between the names php5srvlt and php5servlet.

    In reality, the name of the jar file (phpsrvlt.jar) is irrelevant, since Tomcat will automatically load ANY jar file in the apps WEB-INF/lib directory.

    Through some magic that I don’t understand, the library=php5servlet line tells the classes in the Jar file to call out to the native environment and load the native DLL of the same name (which is why it must be on the PATH)

    Hope this helps - post your response.
    tx
    Jason

  31. Angsuman Chakraborty Says:

    Thanks Jason for the tip. I didn’t realize that people were making the incorrect assumption between the dll file name and the jar file name. I have updated the document to clarify this.

    > Through some magic that I don’t understand, the library=php5servlet line tells the classes in the Jar file to call out to the native environment and load the native DLL of the same name (which is why it must be on the PATH)

    No magic here. Just a simple loadLibrary call to load the native dll. JNI is used here for communicating with the php processor.

  32. Mallika Says:

    I am getting this error repeatedly no matter what I do to resolve it..:(

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    javax.servlet.ServletException: Servlet.init() for servlet php threw exception
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    [snipped]

    root cause

    java.lang.UnsatisfiedLinkError: no php5servlet in java.library.path
    java.lang.ClassLoader.loadLibrary(ClassLoader.java:1517)
    [snipped]

    If I reload the page, it would be

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    javax.servlet.ServletException: Servlet execution threw an exception

    root cause

    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:802)

    I have gone through all the suggestions above and I still could not find where the problem is..can any one help me?

    Thanks,
    Mallika

  33. Meike Says:

    Hi,
    getting PHP to work in Tomcat is exactly what I need. So the above instructions are awsome. But has anybody actually got it to run yet?

    And do you know if the same instructions should work on other platforms such as Unix or Mac OS X. Or if not do you know how to get it to work on other platforms?

    Thanks,
    Meike

  34. Angsuman Chakraborty Says:

    Meiki, I received email from a number of people who were successful in running it. See the comments above also.

    Mallika,
    > java.lang.UnsatisfiedLinkError: no php5servlet in java.library.path

    Ensure that the name of the dll file is the same name that you specified in both the properties file in the jar which you have modified. Please check the instructions again which I have updated to clarify the above issue. Also see the comments by Jason above.

    Hope that helps…

  35. Mallika Says:

    I got it, finally. I was doing mistake in recreating jar file after the changes were made to the .properties files. Thanks anyways, Angsuman. Your article is indeed very helpful.

    - Mallika

  36. Brian Says:

    So I managed to get PHP running on Tomcat 5.5, but im not getting a querky error. After banging on my webserver for only a minute or two, tomcat seems to be crashing and the webpage will display the following error:

    Proxy Error

    The proxy server received an invalid response from an upstream server.
    The proxy server could not handle the request GET /index.php.

    Reason: Error reading from remote server

    Has anyone else encountered this error and does anyone have any ideas on how to troubleshoot it? I’ve checked the Tomcat 5.5 logs and they appear to be ok. After getting this error I have to restart Tomcat to bring it back up again. Any help would me most appreciated. Thanks!

  37. Angsuman Chakraborty Says:

    This error happens when a proxy server is accessed like a normal web server. This has nothing to do with php installation AFAIK.
    Are you accessing the actual tomcat page os are you accessing a proxy server URL instead? Check your port. Tomcat by default runs on 8080. Do you have a proxy server running on your machine?

  38. Brian Says:

    There is no proxy proxy running, and the webserver is running on 8080. the weird thing is that i can view my webpage going back and forth from different pages, and it works fine. Then for some reason, i click on a link which i already verified, and it gives me the error message i previously posted. I’ve done this over and over again, and it seems random where the errors are occuring. Sometimes it on one link, other times it’s on others. I tried this using the jsp pages included in the installation and was unable to reproduce the error, thus why i’m concluding that it must be a problem with the PHP installation. Has anyone else tried doing this installation on Tomcat 5.5.4 using JDK 5.0???

  39. Brian Says:

    So I’ve investigated more and discovered that the proxy error is from my parent server but only because my server is being crashed. I’ve run the same test on my local machine and recieved the following error:
    The connection was refused when attempting to contact localhost:8080
    This appears to be only because the server is down, and doesn’t seem to help much with troubleshooting. But for some reason, on random requests, like i stated in my previous post, the server is being crashed. Any ideas?
    Thanks again!

  40. Brian Says:

    Also, I’ve noticed that php only works when i put the php5srvlt.jar in the common/lib directory and it will not work in the webapps/www/lib directory.
    webapps/www is where my website is located

  41. Angsuman Chakraborty Says:

    Brian,
    I haven’t faced any server crashing issue. The php5srvlt.jar can be in common.lib. It can also be in www/WEb-INF/lib directory where www is your webapps directory. The second way (as mentioned in the post above) is useful for people who use a shared tomcat instance as provided by their hosting provider. Also it allows you to limit the capability to one web application only.

  42. Kai Says:

    Hallo,
    what is meant with Point 15 (add c:php …). I opend SystemEnvironment and added a new systemVariable: name=php and value= c:\php. Is this correct? I ask because I get an error message wehn trying to load the test.php and maybe this is the reason.
    Greets
    Error Message:

    root cause

    java.lang.UnsatisfiedLinkError: send
    at net.php.servlet.send(Native Method)
    at net.php.servlet.service(servlet.java:190

    kai

  43. Angsuman Chakraborty Says:

    Kai,

    Thanks for pointing out the error of missing backward-slash, It happened when I recently edited the post to add some clarifications. In the process I forgot that the post contains some backword-slashes. Now my blog software unfortunately eats away one backward-slash everytime I edit a post. So I have to manually replace each single backward-slash with double. Unfortunately I forgot to do that in this instance. Thanks again for pointing it out.

    Let us know how it goes.

  44. Kai Says:

    So, if this is not the error, I don’t know what’s wrong. I copied php5servlet.dll into c:/php. Than I created the directories and modified the two files. My directory Structure is:
    webapps/fun –> test.php, WEB-INF
    WEB-INF –> lib, web.xml
    lib –> php5srvlt.jar
    But after restarting Tomcat I get the the following error message. And when I reload the website I get the same message with a different root cause.
    I read the posts about this problem, but none of the solutions woked for me.

    1. Exception
    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    javax.servlet.ServletException: Servlet execution threw an exception

    [snipped]

    2. Exception

    root cause

    java.lang.UnsatisfiedLinkError: send
    at net.php.servlet.send(Native Method)
    at net.php.servlet.service(servlet.java:190)
    [snipped]

  45. Angsuman Chakraborty Says:

    Kai,

    Read the comment by Jason above. This problem happens due to improper specification of the location of php5servlet.dll in the properties file.
    Please check the comments above as others have also faced and solved the same issue.

  46. ez Says:

    IMPORTANT: Everybody with an unsatisfied link error double check that you do not have an extra whitespace in the properties files that you change. Servlet.properties and Reflect.properties both have extraneous whitespaces after the names of the dlls.

    Thanks for the great HOW-TO!

  47. Kai Says:

    Hi,
    I read the comments. Also the one of Jason. But still the same error message. Maybe I do something wrong when extracting the phpsrvlt.jar. I’ve opened the file with winrar, made the changes and saved the file without extracting it.

  48. dennis Says:

    HI,
    ich have the same problem like Sachin , how can i solve it?

    2005-02-10 14:51:16,622 [http-8080-Processor25] WARN StandardWrapper[/ikarus_prototype:php] - Servlet.service() for servlet php threw exception
    java.io.IOException: ?l ?l l ?l 
    at net.php.servlet.send(Native Method)
    [snipped]

    10.02.2005 15:00:54 org.apache.coyote.http11.Http11Protocol pause
    INFO: Pausing Coyote HTTP/1.1 on http-8080
    10.02.2005 15:00:55 org.apache.catalina.core.StandardService stop
    INFO: Stopping service Catalina
    #
    # An unexpected error has been detected by HotSpot Virtual Machine:
    #
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0×0c08f185, pid=1640, tid=1912
    #
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_01-b08 mixed mode)
    # Problematic frame:
    # C [php5ts.dll+0x3f185]
    #
    # An error report file with more information is saved as hs_err_pid1640.log
    #
    # If you would like to submit a bug report, please visit:
    # http://java.sun.com/webapps/bugreport/crash.jsp
    #

  49. Angsuman Chakraborty Says:

    Kai,
    Check the jar file again to see if the changes are properly saved. Check the pointer by ez.

    EZ,
    Thanks for the pointer.

    Dennis,
    One simple thought. Please restart the server and see if the error persists. Have you checked the suggestions and hints in the comments section by numerous readers?

  50. dennis Says:

    Thanks Angsuman, it’s works.
    Don’t know why :(
    Yesterday i’ve restarted Tomc@ and Windows several times but without an effect. (got an unexpected error caused by php5servlet.dll)
    But today… hmmmm it’s works! : \

    Are you running your Tomc@ as a service?
    What about JavaVM 1.5 or 1.4?

  51. felix Says:

    I’m also still getting the UnsatisfiedError after checking the *.properties files several times in notepad. also $PATH includes as I can run the command “php” from anywhere. But when trying that I encountered the following error:
    PHP Startup: Unable to load dynamic library ‘./php_java.dll’ - The specified module could not be found.

    which is true as far as i know as there is no such file in c:\php, but when browsing through the files a found a php_java.jar in c:\php\ext. does anyone know what is wrong in my configuration?

    Thank you for this tutorial, i appreciate it :)

    felix

  52. Angsuman Chakraborty Says:

    Felix,

    Check the PECL modules (instruction 2) you have downloaded.

    Thanks for the compliment.

    Angsuman

  53. felix Says:

    Works beautifully :) Thank you again!

    felix

  54. Shawn Says:

    To start off, i have read through each and every post on this thread… Still getting the following error when attempting to load my test.php page.

    Feb 16, 2005 11:31:45 PM org.apache.catalina.core.StandardWrapperValve invoke
    WARNING: Servlet.service() for servlet php threw exception
    java.io.IOException: `R,`R,hR,TV,?
    at net.php.servlet.send(Native Method)
    [snipped]

    I noticed Sachin had this problem, and resolved it somehow …? Any help would be most appreciated.

  55. Angsuman Chakraborty Says:

    One simple thought. Please restart the server and see if the error persists.

  56. Guto Says:

    I followed the steps but…

    javax.servlet.ServletException: Wrapper cannot find servlet class net.php.servlet or a class it depends on
    [snipped]

    root cause

    java.lang.ClassNotFoundException: net.php.servlet
    [snipped]

    what should i do????

  57. Meera Says:

    Hi Angsuman,
    Your tutorial has been a great help.
    but i still have the
    java.lang.UnsatisfiedLinkError: no php5servlet in java.library.path
    error.
    i have read all the comments above and done the necessary changes.
    when i recreate the jar (jar cvf php5srvlt.jar net/php/*.* ) the class files are not getting created (servlet.class, reflect.class) which were there before. what should i do?
    any help would be really appreciated.
    thanks a lot
    Meera.

  58. Meera Says:

    Hi,
    i want to use the SAPI module in php to make a servlet running in tomcat handle a php request.
    any pointers about how to go about this would be really helpful.
    thanks a lot.

    Meera.

  59. Angsuman Chakraborty Says:

    Guto,
    Check to see the jar file is under the WEB-INF\lib directory as required.

    Meera,
    Looks like you are not creating the jar file properly with changes. Please follow the steps exactly. Also please check my comment on 1/2/2005 on the same topic.

  60. Dlfiles Says:

    First of all, thanks Angsuman for the tutorial and also the people that have replied with tips. ^_^

    I had that “java.lang.UnsatisfiedLinkError: send” error for a while and the solution was simply to completely restart the tomcat server.

    Now it works fine but every time I go to localhost:8080/fun I can see the index.php as if it didn’t auto-recognize the file! Anyone has any idea how to fix this?

    Note: I know to fix this on an Apache server you would do something like “DirectoryIndex index.html index.html.var index.php ” but for Tomcat I have no clue.

    thanks.

    Dlfiles

  61. Meera Says:

    hi,
    Thanks for tip. I no longer have the UnsatisfiedLinkError.
    But this is the error i get when i try to run any php program inside the fun directory. If i place a php file in the root directory, it is not getting parsed. ( the dialog box offering to save or open the file appears)

    java.io.IOException: ¸2Bm
    at net.php.servlet.send(Native Method)
    [snipped]

    thanks,
    Meera.

  62. Angsuman Chakraborty Says:

    Meera,
    As DlFiles mentioned before you:

    I had that “java.lang.UnsatisfiedLinkError: send” error for a while and the solution was simply to completely restart the tomcat server.

  63. Angsuman Chakraborty Says:

    Dlfiles,

    Add the following at the end of the web.xml of your web application, before the </web-app> tag.


    <welcome-file-list>
    <welcome-file>index.php</welcome-file>
    </welcome-file-list>

    You can similarly use other extensions too. The default extensions are jsp, htm and html, defined in conf/web.xml.

  64. Dlfiles Says:

    Angsuman,

    Everything is working fine now! thanks again!

  65. Brian Says:

    FYI, I just tried using the web.xml you have listed above and the servlet did load. I removed the DOCTYPE line and it worked. I think you may have something wrong with your slashes possibly. However, the doctype isn’t required.

    P.S. thanks for all the help, your tutorial is excellent!

  66. Brian Says:

    So i’ve reinstalled everything and I’m getting random errors killing the Tomcat server still. in my system32 folder there is a log which is printing out the following… any ideas??? it looks like there is an error in php5ts.dll.

    #
    # An unexpected error has been detected by HotSpot Virtual Machine:
    #
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0×0583eced, pid=832, tid=3472
    #
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_01-b08 mixed mode, sharing)
    # Problematic frame:
    # C [php5ts.dll+0x3eced]
    #

    ————— T H R E A D —————

    Current thread (0×032b1438): JavaThread “http-8080-Processor25″ daemon [_thread_in_native, id=3472]

    siginfo: ExceptionCode=0xc0000005, reading address 0×00000016

    Registers:
    EAX=0×035c5668, EBX=0×00000002, ECX=0×00000002, EDX=0×00000007
    ESP=0×051fef64, EBP=0×77c2c21b, ESI=0×05c1c6c8, EDI=0×035c5668
    EIP=0×0583eced, EFLAGS=0×00010297

    Top of Stack: (sp=0×051fef64)
    0×051fef64: 05c1c6c8 051ff120 032b3998 0585fe90
    0×051fef74: 00000002 05c1c6fc 0583b7dd 05c1c6c8
    0×051fef84: 05c1c6f0 0583ee74 05c1c6fc 051ff118
    0×051fef94: 035c5668 051ff120 032b3998 0583ef43
    0×051fefa4: 035c5668 05c1c6f0 035c56f8 0583b039
    0×051fefb4: 035c5668 035c57f4 032b3998 05b48660
    0×051fefc4: 0583b5f0 032b3998 035c56f8 051ff1f8
    0×051fefd4: 032b3998 032b1438 032b1438 00000006

    Instructions: (pc=0×0583eced)
    0×0583ecdd: 90 90 90 53 8b 5c 24 08 55 8b 2d 18 a2 9f 05 56
    0×0583eced: 8b 73 14 85 f6 74 51 57 8b 43 20 8b fe 8b 76 10

    Stack: [0x05100000,0x05200000), sp=0x051fef64, free space=1019k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    C [php5ts.dll+0x3eced]

    Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
    j [Truncated]

  67. Brian Says:

    So I’ve reinstalled everything and I’m still getting the same problems where after clicking a bunch of links on my page, my Tomcat server crashes. there is an error log in my system32 folder that is printing out the following. it looks like there is an error in php5ts.dll… and ideas???

    #
    # An unexpected error has been detected by HotSpot Virtual Machine:
    #
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0×0583eced, pid=832, tid=3472
    #
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_01-b08 mixed mode, sharing)
    # Problematic frame:
    # C [php5ts.dll+0x3eced]
    #

    ————— T H R E A D —————

    Current thread (0×032b1438): JavaThread “http-8080-Processor25″ daemon [_thread_in_native, id=3472]

    siginfo: ExceptionCode=0xc0000005, reading address 0×00000016

    Registers:
    EAX=0×035c5668, EBX=0×00000002, ECX=0×00000002, EDX=0×00000007
    ESP=0×051fef64, EBP=0×77c2c21b, ESI=0×05c1c6c8, EDI=0×035c5668
    EIP=0×0583eced, EFLAGS=0×00010297
    [snipped]

  68. Brian Says:

    im having trouble posting to your site maybe my post is too long… im trying to include an error log message

  69. angsuman Says:

    Brian,
    Sorry for the delay in responding. The comments were getting gobbled up by a defective filter in WordPress 1.5 ( more on it soon ). I am looking at your problem now.

  70. angsuman Says:

    Brian> I think you may have something wrong with your slashes possibly. However, the doctype isn’t required.

    You are correct. WordPress 1.5 messed up the double-quotes. I have removed them now. Thanks for the information.

  71. angsuman Says:

    @Brian Why is php5ts.dll in your path? I don’t remember seeing that.

  72. Kyle Says:

    Your tutorial was of great help in getting php connected, but only seems to work for the first php applicaiton that I hit on my web server.
    For instance if I copy webapps\fun to webapps\fun2 and restart Tomcat (4.0.6) and then access either of them, it works. But when I access the other one I get an error message:

    java.lang.UnsatisfiedLinkError: Native Library C:\php\php5servlet.dll already loaded in another classloader

    I tried moving the jar file into the common\lib and modifying the web.xml in the conf directory to include the servlet ans servlet-mapping directives, but can’t seem to find the right twist for it.

    Starting service Tomcat-Standalone
    Apache Tomcat/4.0.6
    ERROR reading java.io.ByteArrayInputStream@161dfb5
    At Line 11 /web-app/servlet/

    Starting service Tomcat-Apache
    Apache Tomcat/4.0.6

  73. Kyle Says:

    Ah, “already loaded in another classloader” problem solved.

    Move the php5srvlt.jar file out of the tomcat directory and put it in the Java jre/lib/ext directory
    (C:\Java\j2sdk1.4.2_07\jre\lib\ext on my PC)

  74. angsuman Says:

    Are there anyone who commented on this post who couldn’t get it to running yet?

  75. Manisha Mangal Says:

    java.lang.UnsatisfiedLinkError: send

  76. angsuman Says:

    @Manisha Please repeat step 6 & 11-15. I short you probably do not have the dll file extracted in proper place. But first restart the server and test again. Restart by itself may solve the problem as has happened for many.

  77. Vincenzo Fazi Says:

    Tanks for your step by step tutorial. I had it working, with Tomcat 5.0.19 and php 5.0.4. I spend a lot of time due to an error defining the PATH environment variable to add the php path, and even after the correction it was using the old setting. A boot fixed it. The only problem left is that running the test.php with the phpinfo() it does not disply the tho icons PHP Logo and Zend logo. Any idea?

  78. angsuman Says:

    @Vincenzo
    Where are the image url’s pointing to?

  79. Vincenzo Fazi Says:

    I think they are embedded into php5ts.dll that is in the main dir of php (d:\PHP5). Viewing the source the relative tag is the following:

  80. Vincenzo Fazi Says:

    The html code has been removed from the previous message. Substitute the square brackets with the angle brackets in the following line:
    [a href="http://www.php.net/" ][ img border="0" src="/fun/test.php?=PHPE9568F34-D428-11d2-A769-00AA001ACF42" alt="PHP Logo" /][/a]

  81. angsuman Says:

    @Vincenzo
    It shouldn’t affect your applications in any way which is good. However if you still want to fix it read on.

    I did several installations, never faced it. So I was wondering if you could please re-check the steps to see if you are missing any small details. Looks like the problem may be with your PHP configuration.

  82. vijay Says:

    Hi, all
    I’ve tried everything which is possible but still couldn’t get the php configured for the tomcat.

    I’ve tried all the options, changing the servlet,reflect.properties but getting the specific error as:

    “Exception is — > javax.servlet.ServletException: Servlet.init() for servlet php threw exception”

    Infact I’ve restarted the tomcat server,but still not getting.
    Plz help.

    Regards
    Vijay

  83. angsuman Says:

    What is the exception?

  84. Orcun Says:

    Hi,
    Thansk angsuman for this article but i couldnt make it work! I’ve done everything you wrote, but everytime i come up with the common error:
    HTTP Status 500 -

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    javax.servlet.ServletException: Servlet execution threw an exception

    root cause

    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:802)

    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
    [snipped]

    What should i do? Can you help? Thanks

  85. angsuman Says:

    Please see the comments and responses above.
    To quote from my comment:

    As the jar file is placed under web-inf/lib directory realoding the web container causes the dll to be reloaded again which fails.
    The simplest solution is to restart the server whenever there is a need to restart the web container. However to eliminate the problem totally you can place the jar under common/lib directory. That way it is loaded the tomcat classloader and is not restarted when the web container is restarted.
    Let me know if that helps.

  86. Orcun Says:

    I’ve moved the jar file into the common/lib directory but the same error appeared again.

    HTTP Status 500 -

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    javax.servlet.ServletException: Servlet execution threw an exception

    root cause

    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:802)

    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
    [snipped]

    I’ll try to make a fresh start…

  87. angsuman Says:

    @Orcun

    Re-check steps 6 & 11-14.
    > 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

    Also ensure php_java.dll is under c:\php

    The problem is happening because it cannot find the dll file under php directory.

  88. sal00m Says:

    first of all, sorry about my poor english, i’m spanish :), and thx for the article ;)

    angsuman, copy the file php_java.dll in “extensions” and problem is solved (hope it helps. I think this is the problem

    i have a problem with the process, when i try to load the index.php (the page with php_info()) i have and exception.

    The exception is:

    06-may-2005 11:37:14 org.apache.catalina.core.StandardWrapperValve invoke
    GRAVE: Excepción de reserva de espacio para servlet php
    java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet

    help please… thx in advance

  89. angsuman Says:

    BTW: I am Bengali :)
    I think your Tomcat hasn’t been installed properly in the first place. Can you run the example servlets & jsp?

    > java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet

    This is actually a core jar file which is part of the installation.

  90. orbknives Says:

    heloo there Angsuman Chakraborty!!!

    Nice guide!But a litle prob here, as the same with others, the error:

    javax.servlet.ServletException: Servlet.init() for servlet php threw exception
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    [snipped]

    root cause

    java.lang.UnsatisfiedLinkError: no php5srvlt in java.library.path
    [snipped]

    always appearing, i dont know now what to do, im stuck, i did followed your guide neatly but dont have any clue!!!Please help, i actually need to run some php in jakarta!!!Thanks…

    P.S what j2sdk version, and tomcat version will work the best in this guide??Because someone here in our work required me to use j2sdk-1.4 and not the latest one (1.5).. And we are using tomcat 4.1.31 / 5.0.28.. Please help me… :(

  91. Angsuman Says:

    @orbknives Please check mine (comment No 87 and before) and others comments above which explains the solution clearly. AFAIK it solved it for all.

    In short check item no 5, 6 & 11-14.

    The php jar file is trying to load the dll (whose name you specified in 11-14) and failing.

    After verification of the above, just add c:\php to your system path (just to be safe).
    Restart Tomcat and try again.

    Let me know how it goes.

  92. orbknives Says:

    Ok thank you for the quick reply!!Actually i already read the whole thread, i seen same problem and i also followed those instructions but how come it didn’t work for me.. Do i need to used a specific version of JAVA of Tomcat?? Im using j2sdk1.4.2_07 and tomcat 5.0.28..In the no. 5 & 6, yes i created a copy of php.ini-dist and renamed it as php.ini (Uncomment the line ;extension=php_java.dll ) and paste back it at c:\php. I also check that the php5servlet.dll (from pecl.zip) is in th c:\php..

    On the 11 - 14, yes i extracted and created again the php5srvlt.jar using

    to unjar -> “jar xfv phpsrvlt.jar”

    to Recreate -> “jar cvf php5srvlt.jar net/php/*.*
    (are these are correct??)

    Ofcourse before i recreated the jar i edited the reflect.properties and servlet.properties to change the line library=phpsrvlt to library=php5servlet (question: do i need to include the ‘.dll’ or just the php5servlet?) and i also checked that theres no left white spaces/lines. After the jar was created i paste it in WEB-INF\lib.. i even tried pasting it at tomcat\common\lib but same result…Bout the System variable, the NAME i inputed is PHP (uppercase) and C:\php for the value, is this correct??Thats all i did.. What could be the problem??What should i do next?i hope you will still help me till we fix this… Thanks…

  93. Angsuman Says:

    Verify that the configuration files are being jar’ed to the same directory structure.

    How?
    Rename the original jar file as .zip and open it in Winzip etc. Note the directory structure aka path of the configuration files. Ensure that it is the same after you have re-jar’ed the file

    Versions of Tomcat and JDK are fine.

    Try adding c:\php to the beginning of the PATH variable in System Properties.

  94. Angsuman Says:

    Are there anyone else who still have problems setting this up?

  95. orbknives Says:

    Angsuman thanks a lot!!Its working now!!!i owe you one!!!By the way is it possible to do this in linux??Ever planned to create a guide for linux too??

    Also, can i ask something bout php?and jnlp files, can i include a php script inside a jnlp file?Where my script is a sql query, when the condition is not met, the php script will block the execution of the jnlp..Any idea?Is this possible??????

  96. Angsuman Says:

    > By the way is it possible to do this in linux?
    Sure. Why not? You just have to use shared objects (.so files) instead of dll’s. Normally though people, including myself, prefer running Apache server and configuring Tomcat to run with it and also php to run with it. It is much simpler that way.

    You can refer to 5 Simple Steps to Integrate Tomcat 5.5 with Apache 2.0

    > can i include a php script inside a jnlp file?Where my script is a sql query, when the condition is not met, the php script will block the execution of the jnlp..Any idea?Is this possible??????

    Why not use a Filter to check the sql query before serving any jnlp file?

  97. orbknives Says:

    So in linux, shared objects are the key, but will your guide be applicable if il try it on linux??Bout the tomcat-apache, is it stable and reliable??Also i dont want to hi-jack this thread but im hardly in need of help now. So use a Filter to check the sql query before serving any jnlp file, actually im a newbie in php, so any idea how can i block or prevent to execute jnlp files where in my main.php file has some hyperlinks directly to the jnlp (file.jnlp)..The only solution i see is include a php script in the jnlp, but i don’t know how to block the execution of that jnlp when it was click, something like this, (consider this as a jnlp)..

    if (!$authentication)
    exit(1);
    some scipt here

    So any idea?Or anything you think that can secure a jnlp file from executing if the condition was not met, ofcourse using php?? Again, Thanks!!!!!

  98. Rick Says:

    I’m having trouble getting this to work. I’ve been at it for a couple of days, reading and re-reading all the posts. I’ve made it past the UnsatisfiedLinkError problem and am stuck on an java.io.IOException: ¸2Bm
    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:853)

  99. Angsuman Says:

    @orbknives
    On Linux:
    Tomcat is very stable and production grade.
    Tomcat-Apache combination is very stable and production grade.

    You will have to make some common sense changes, but overall the same idea is applicable on Linux too.

    I am assuming you will be serving JNLP file over a Tomcat server. Then you need to setup a Filter for .jnlp extension. In the filter code (java) you do whatever check is necessary. If the check succeeds then the user is able to download the jnlp file.

    @Rick
    First though. Restart Tomcat and check again. If that doesn’t fix it, let me know.

  100. Rick Says:

    Have restarted Tomcat (actually using JBoss with embedded Tomcat) several times to no avail.

  101. Angsuman Says:

    Is your exception identical to Meera’s IOException above?

    Are you able to run normal JSP files from this web directory?

    It is trying to load some filter which is not correct. It shouldn’t be loading any filter. Looks like a setup issue with Tomcat.

    Can you find out the version of Tomcat you are running?

  102. Alberto Says:

    Hi, i’m getting the following famous error when running Tomcat 5.5.4 and PHP 5.0.4:

    java.lang.UnsatisfiedLinkError: send
    net.php.servlet.send(Native Method)

    I swear I have followed all the steps: I changed the properties in phpsrvlt.jar to “php5servlet”, and placed that jar in common/lib. I also put php5servlet.dll in the php folder.
    Do you think the problem may have to do with some CLASSPATH stuff? Thanks in advance.

  103. Angsuman Says:

    Please check my comments 91 & 93. orbknives was recently having the same problem and it was solved.

    Maybe orbknives can also provide you some pointers…

  104. Anuj Says:

    Hello Guys,

    I was trying to install my php 5 under tomcat 5.
    I read the complete converstation as I was also facing the same problem of servlet like..

    root cause

    java.lang.ClassNotFoundException: net.php.servlet
    [snipped]
    ——————

    Finally i got the solution..

    It was suggested in the first message by Angsuman that after making the changes in the properties file, recreate the jar file using jar…

    I did the same way but when i saw the size of the new jar file and compared with the size of old jar file, it was varying a lot.

    So i opened my old-jar file in the winzip and opened the properties files and made the changes and then saved them on the hard-disk in c:\net\php\

    Then in my winzip window i added those files by clicking the add button. Dont forget to check the check box which says “save full path info”. Doing this replaced my properties files in the jar files with the new files i saved on the hard disk.

    I did the same way with both the files and got my same jar file modified with the required changes.

    This time my jar file was approx of the same size.

    Rest all i did same as suggested by Angsuman and it worked properly..

    Thanks
    Anuj

  105. Angsuman Says:

    Thanks Anuj.

  106. Alberto Says:

    Angsuman, I just got it working all toghether. The reason of the failure was that I had forgotten to place the php5servlet.dll in the windows/system folder. Thank you for your help and for using your time in helping other people ;)

  107. xcell Says:

    hey Angsuman, thanks for of this and to me this would be great if i could finally get it to work…

    unfortunatly I can only get : java.lang.UnsatisfiedLinkError: no php5servlet in java.library.path

    to me i did all your step but there are just a few things i want to make sure :

    1 - in step 15 you say : Add c:\php to your System or User Path in Windows enironment (Hint: Right-click and select Properties from My Computer)

    but what name should I give it? php?

    2 - library=php5servlet… no lines or spaces after right?

    3 - i moved the php5srvlt.jar from fun/WEB-INF/lib to commun/lib and then back again… no changes there

    4 - phpsrvlt.jar is 16kb, but when I rejar it to php5srvlt.jar it goes down to 9kb…. i did what anuj says but it didnt change anything… my php5srvlt.jar is now 16kb thou…

    hope there is something I missed here and can be fixed…

    thanks for all your great work and the inout from everybody else… seems that i just cant see the light…

  108. Angsuman Says:

    Please see all the comments and discussion above.

    You missed step 15. You just need to add c:\php to existing PATH variable.

    2. Yes

    4. Open it and make sure the path of the config files are same as before.

  109. hypergori Says:

    I have been keeping getting the
    “UnsatisfiedLinkError problem”.I almost gave up.

    But, after reboot PC(Win2Kserver) , it works fine.
    Maybe rebooting tomcat is not enough to
    reset the PATH environment variables.

    Angusman,Thank you for very usefull article!

  110. haudv Says:

    I have below problem (like Sachin, Dennis,..). I also restart server many times but the problem doesn’t go away.

    When I stop/start tomcat service and refresh the page (http://localost:8080/fun/test.php), system shows the warning “Module Java already loaded” (a popup message).

    Help me!

  111. haudv Says:

    I have below problem (like Sachin, Dennis,..). I also restart server many times but the problem doesn’t go away.

    java.io.IOException: ‡j‡j ‡j ‹j€
    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:802)

    When I stop/start tomcat service and refresh the page (http://localost:8080/fun/test.php), system shows the warning “Module Java already loaded” (a popup message).

    Help me!

  112. Angsuman Says:

    @haudv
    Please double-check the instructions.

    Please refer to the comments above for additional information and clarifications.

    Try restarting the machine.

  113. akhilesh Says:

    exception

    javax.servlet.ServletException: Servlet execution threw an exception
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)

    root cause

    java.lang.UnsatisfiedLinkError: no php5servlet in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1410)
    [snipped]

    i’ve tried all the given solutions but none worked except this suggested by Mr. Bahrat Soni

    “only system variable will work for php path setting , if u have created a user variable then it won’t work and will give such exception so add the path c:\php in ur system variables……”

  114. Arundhati Says:

    Hello All,

    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.

  115. pdb Says:

    ARUNDHATI, thank you very much!!
    The issue are the blank spaces!!!

    I suggest Angsuman to update the instructions… And, of course, thank you a lot too, Angsuman

  116. Angsuman Says:

    The post has been updated with Arundhati’s comment. Thanks Arundhati.

  117. lfr Says:

    Thanks for the instructions. I followed them and aftyer a few tries it works. Well, most of the time.

    I have a problem that when I send a POST messages with somehow large pieces of text (22K of XML code to be precise) it crashes Tomcat (5.0.18). Basically it hangs and after a while it dies. I tested the same files in a Linux installation and it ran fine.
    Has anybody found a similar problem? Is it a bug with php’s servlet implementation? Or do you think I have a problem with my installation?

    I appreciate any help

    Thank!

  118. Angsuman Says:

    @lfr
    It doesn’t look like an installation problem. try upgrading to Tomcat 5.5 and see if that helps.

    That 22K is it for some php file or just to an ordinary servlet?

    BTW: If you have any suggestions on improving the instructions let me know.

  119. Felix Says:

    Awesome tutorial! Thank you very much. I would suggest that instead of adding C:\php to the path (as suggested in step 15) you may want to modify your Tomcat Properties (Start-Programs-Tomcat-Configure Tomcat), in Java tab add a line to Java Options: -Djava.library.path=C:\php or similar.

    Also, I have the same problem as in posts 79-80: the pictures in phpinfo() are not coming through. I don’t know if anybody figured out what can be causing it.

  120. Angsuman Says:

    @Felix
    That is a good idea. Having it in path is actually useful for other scenarios also like when you want to test your php scripts on command line. The reason I included it in path is bacause it makes installation simpler.

  121. Sam Says:

    Great tute, thanks Angusman!!

    OK..Well so that I wouldnt be *bitten* I read the tute maticulously..and even went through a hefty amount of questions.. though when I tried it all out.. I received the error “UnsatisfiedLinkError…”

    The problem is that for some F&*&*& reason, the User Path or System Path is not correctly refreshed in my environment.. SOO when I rebooted the machine (win xp pro sp 2) it worked fine!

    I JUST REALISED.. the shell (dos window) that I was running stop and start for the Tomcat Apache Service would have probably *NOT* been updated with the new Environment variables hence why I kept getting this error.. maybe if I had opened another dos window and re-issued the net stop/start tomcat5 command it would of worked.. anyways by rebooting it all worked fine which leads me to believe its just a PATH issue..

    Thanks again

    Sam

  122. Sam Says:

    Sorry.. just a quick one.. is it possible to use openLDAP with PHP and tomcat in windows ??

    Thanks

    Sam

  123. Thomas Says:

    nice tutorial. Thanks,
    It seems to be working mostly correct. the phpinfo() outputs almost everything to the webpage, but my last few _ENV variables show up in the command window where the tomcat server startup info is displayed. Trying to output anything else sends it directly to the command window and the webpage comes up blank. Any help on this would be greatly appreciated.

    Thanks.

  124. Sam Says:

    Hi,

    I thought I had successfully configured php for tomcat in windows as when I invoked:

    It seemed to work fine..

    HOWEVER.. when I tried to issue a echo “BLAH”; nothing happends.. I have tried this on my work and home computer and the same results.. I have a requirement to build a php application to talk to our LDAP server..

    Soo in short php is not working as I thought it would work.. Even when I put some html code outside the php tags nothing is rendered, nothing in view-source..

    Any ideas??

    Thanks

    Sam

  125. Sam Says:

    Sorry before when I said I invoked it ommitted the actual command which was phpinfo();

    Thanks

    Sam

  126. Angsuman Says:

    Wonderful. So you are done.

  127. John Says:

    Thanks very much for this information. I now have a Lotus Domino server serving the public with tomcat\php running behind the scenes locally to generate jsp and php pages. Absolutely awesome!!!

  128. Mad Says:

    Just solved the link error problem, like Sam above, by rebooting (also XP Pro SP2). Might the problem be in running Tomcat as a service? Starting and stopping is not enough. Thanks for really good page and your patience with all of us :-)

  129. prasad Says:

    Loaded PHP and tomcat and followed all the steps.
    But Blank sceen is being displayed when I am running the test.php page.

  130. Elmer Says:

    Hi everyone, i had this problem for the longest time:
    java.lang.UnsatisfiedLinkError: no php5servlet in java.library.path

    I set the %PATH% to c:\php but it still would not find it.

    If any of you are using Tomcat monitor, try adding c:\php to the working path in configurations. This solved the problem for me.

    Restart and try it. Hope this helps.

    Thanks for the tutorial

  131. Angsuman Says:

    @Elmer
    Good to know it worked for you.

    I did mention that in comment 91 above.

    After verification of the above, just add c:\php to your system path (just to be safe).
    Restart Tomcat and try again.

    @Prasad Please re-check the steps carefully. Also take some time to read the comments as there are valuable hints there. Let me know if the problem still persists.

  132. frustrated Says:

    After long frustration I’ve almost gotten it to work. But I’m still getting: java.lang.UnsatisfiedLinkError: no php5servlet in java.library.path

    I already removed the blank spaces so it’s not that. I also have C:\PHP\ in windows’s environment variables.

    I also tried to add the native libraries with VM flag -Djava.library.path=C:\PHP\
    But this results into:
    java.lang.UnsatisfiedLinkError: C:\PHP\php5servlet.dll: Can’t find dependent libraries

    Anyone?

  133. frustrated Says:

    OK, it worked after rebooting computer. After that I was getting lots of weird errors like ClassLoader already in use etc. and they all vanished after switching from Mustang to Tiger.

    Thanks for a nice article

  134. frustrated Says:

    … actually I was wrong and I guess lucky or something as it now still crashes when reloading pages (but with JDK 6.0 most of my php pages didnt actually work at all). I scrolled up and read the comments and tried to copy the php5srvlet.jar to tomcat/common/lib but it didnt help :( - still getting java.lang.UnsatisfiedLinkError: Native Library C:\PHP\php5servlet.dll already loaded in another classloader. So it shouldn’t copy the jar to web-inf/lib this way? Because it still does. Maybe it’s got something to do with the fact that i’m using Intellij IDEA’s Tomcat integration. I’m so new to all this. Sorry if this has been mentioned in some comments above but i tried to glance through them and didnt find solution.

  135. Rich Says:

    This How-To is awesome. It helped me get jump started quickly with what I needed to do. I will add this though. For anyone who is having quirky problems and you know that you have everything right try rebooting your machine. As simple as that sounds it solved the problem I have been wrestling with for the last 2 hours.

  136. Kevin Says:

    Some1 please help I’ve tried to install this multiple times to no avail. When i run that test page i get

    displayed and thats it. Anyone know the solution for this?

  137. Kevin Says:

    for above

  138. Kevin Says:

    php phpinfo();

  139. Angsuman Says:

    @Kevin
    That is not proper php. Try this:
    <?php phpinfo(); ?>

  140. Angsuman Says:

    Thanks Rich.

  141. Kevin Says:

    nah it was like that but it wouldnt let me post with the tags. But i got past that error, now im stuck at the
    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    javax.servlet.ServletException: Servlet.init() for servlet php threw exception
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)

    root cause

    java.lang.UnsatisfiedLinkError: C:\PHP\php5servlet.dll: Can’t find dependent libraries
    java.lang.ClassLoader$NativeLibrary.load(Native Method)
    [snipped]

    I have made sure there aren’t any spaces in the properties files, i recreated the jar file, ive tried restarting, tried moving the jar file to the common lib. Still got nothing :( Thanks in advance

  142. Angsuman Says:

    Please double-check the instructions to ensure you have done everything as detailed. Then check the comments above for sugestions.
    However first try to reboot your machine and see if it solves the problem.

  143. Surtr Says:

    Hi all,

    I wrestled with the following issue for two days and then finally found a solution to it.

    I kept getting this error over and over again and tried everything that people had suggested on this site, but no use. “java.lang.UnsatisfiedLinkError: C:\PHP\php5servlet.dll: Can’t find dependent libraries”

    Finally I got pissed with everything and started doing thigns the difficult way. It turned out that the solution would eventually have saved me many hours of useless configuring.

    I found an application called “Dependency Walker” (go google it) and did a dependency search on the php5servlet.dll. It turned out that I was really missing one dll in my system: msjava.dll, This file I then downloaded from the http://www.dll-files.com. Now EVERYTHING is running smoothly.

    I hope that this post helps you guys all!

    Enjoy :)

  144. Angsuman Says:

    @Surtr
    Did you have JDK installed in your machine? It appears that was not the case. Otherwise with JDK (and JRE) installed you shouldn’t need that dll.

  145. Surtr Says:

    Yes,

    Sorry to be this late with my answer, but here it comes anyways :)

    I have JDK 1.5.0_05 installed. In addition have the enterprise edition on my machine for development purposes.

  146. Aaron Says:

    Just thought Id publish this tip since I got these instructions pretty much working out of the chute, but ran into an issue posted above. The test.jsp page worked fine for me as phpinfo() would display correctly on my tomcat server. However, all other php pages were being output to the tomcat console window. I realized that I used the php.ini-recommended file as my php.ini, since I started to read the php installation instructions before this page. After diff’ing the two files, I found the culprit variable. Turn the setting:

    output_buffering = Off

    in your php.ini and all should work fine. output_buffering should be set to off.

  147. Joseph Says:

    Might be outside the scope of this thread, but I was hoping someone might be able to point me in the right direction.

    I am able to get PHP (using 5.0.5) to work with my tomcat install (5.0.28). However, for some reason I can’t get the php pages to connect to MySQL. I’ve followed directions in other posts about uncommenting the extension and where to place the php_mysql* and libmysql files, but I still get an error message about mysql_connect not being valid. Anyone have any suggestions or know of any problems with this kind of setup?

  148. siberian Says:

    hi, I have managed to install php on tomcat.But it doesn’t work properly.
    works.But other content of a page will not be dispalyed on the browser, it is displayed on the console of tomcat:(
    That is, I have a file named test.php:

    hello

    if I try to access it, phpinfo prints php infomation in detail, but “hello” is not showed! Instead the tomcat console prints “hello”.
    I have tried phps from opensource php project( to make sure the problem is not my php file), they fail too

    php version is 5.05 tomcat is t.0.28
    And idea what is the problem?

  149. siberian Says:

    sorry, my last message doesn’t display properly.
    should be:
    I have a file named test.php:
    [?php phpinfo();?]
    hello

    (I have change

  150. siberian Says:

    so sorry for mess it up>.

  151. Kevin II Says:

    Can anyone who solved the “Module java already loaded” issue please post their solution.

    I am abont to pull my hair out with this problem. I have gone through the steps at least a dozen time. I have removed and reinstalled java, tomcat, php, restarted the server, restarted tomcat, same problem.

    I am running Tomcat 5.0.28, php 5.0.5 and jre-1_5_0_04 on win2k. I really need help with this.

    java.io.IOException:
    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:802)

    Thanks
    Kev

  152. Edur Says:

    Angsuman, thanks for your wonderful guide. It’s been very useful to me.
    It works right, no problems at all.
    To Kevin II: I’ve got the “Module java already loaded’ error too. As I had an o