UPDATE APRIL 2011:
This is an old post and as such is not current for PHP or Tomcat as they are today. Please do not follow this post's instructions as they are now likely out of date.
More current information can be found at
http://wiki.apache.org/tomcat/UsingPhp
I would in fact now recommend simply running Quercus PHP:
http://www.caucho.com/resin-3.0/quercus/
Thank you,
-Chris.
Sometimes, you want to run PHP with Tomcat. Why? Well, you may have a legacy product, for instance, that will require servlets for many more years. Or you may be using this gigantic Java program and are only interested in adding a tiny PHP piece on the side.
There are many guides showing how to do this available, but they become outdated almost as soon as they are published. So, it's my turn to write a short-lived guide, this time for PHP 5.2.5 :)
Note thas this post relies greatly on information found here. Too bad even that guide got old so fast!
php
net.php.servlet
php-formatter
net.php.formatter
php
*.php
php-formatter
*.phps
library=phpsrvltlibrary=php5servlet
@chrisfr
@Chris FR
@chrisfr
@Chris FR
@chrisfr
@Chris FR
Comments
Hi!! Thanks, very nice effort. I was successful setting up php5.2.5 / tomcat5.5 on windows xp. One small suggestion is that in step(0 or 10), instead of jar-ing/un-jar-ing I managed by renaming the php5servlet.dll to php5srvlt.dll and got ride of the famous "Unspecified Link" exception. A point to mention is that that "TOMCAT" does not seem use system classpath, you have to feed in -Djava.library.path(for pointing to php) when you start the service on windows.
Link / ReplyComment awaiting approval 5 months, 2 weeks ago
Comment awaiting approval 4 months, 4 weeks ago
Comment awaiting approval 4 months, 4 weeks ago
Comment awaiting approval 4 months, 2 weeks ago
Comment awaiting approval 4 months, 2 weeks ago
Comment awaiting approval 4 months, 2 weeks ago
Comment awaiting approval 4 months, 2 weeks ago
Comment awaiting approval 4 months, 1 week ago
Comment awaiting approval 4 months, 1 week ago
Comment awaiting approval 4 months ago
Comment awaiting approval 4 months ago
Comment awaiting approval 3 months, 3 weeks ago
Comment awaiting approval 3 months, 3 weeks ago
Comment awaiting approval 3 months, 3 weeks ago
Comment awaiting approval 3 months, 2 weeks ago
Comment awaiting approval 3 months, 2 weeks ago
Comment awaiting approval 3 months, 2 weeks ago
Comment awaiting approval 3 months, 2 weeks ago
Comment deleted 3 months, 1 week ago
Comment deleted 3 months, 1 week ago
Comment deleted 3 months ago
Comment deleted 3 months ago
Comment deleted 3 months ago
Comment deleted 2 months, 3 weeks ago
Comment deleted 2 months, 3 weeks ago
Comment deleted 2 months, 3 weeks ago
Comment deleted 2 months, 3 weeks ago
Comment awaiting approval 2 months, 2 weeks ago
Comment awaiting approval 2 months, 2 weeks ago
Comment awaiting approval 2 months, 2 weeks ago
Comment awaiting approval 2 months, 2 weeks ago
Comment awaiting approval 2 months, 1 week ago
Comment awaiting approval 2 months, 1 week ago
Comment awaiting approval 2 months, 1 week ago
Comment awaiting approval 2 months, 1 week ago
Comment awaiting approval 2 months ago
Comment awaiting approval 2 months ago
Comment awaiting approval 2 months ago
Comment awaiting approval 2 months ago
Comment awaiting approval 2 months ago
Comment awaiting approval 2 months ago
Comment awaiting approval 2 months ago
Comment awaiting approval 1 month, 4 weeks ago
Comment awaiting approval 1 month, 4 weeks ago
Comment awaiting approval 1 month, 3 weeks ago
Comment awaiting approval 1 month, 3 weeks ago
Comment awaiting approval 1 month, 3 weeks ago
Comment awaiting approval 3 weeks, 6 days ago
Comment awaiting approval 3 weeks, 5 days ago
Comment awaiting approval 3 weeks, 3 days ago
Comment awaiting approval 2 weeks, 4 days ago
Comment awaiting approval 2 weeks, 3 days ago
Comment awaiting approval 2 weeks ago
Comment awaiting approval 1 week, 6 days ago
Ha! I was wondering if merely renaming the DLL would work. Thanks!
Link / ReplyThanks -- the test.php works fine with phpinfo(), but other scripts show nothing in the browser or in the page source. Any thoughts? Kevin
Link / Replythe phpinfo works BUT if you run any other *.php file they show a blank page
Link / ReplyI was trying to run php5 on tomcat 5.0 using the above intructions. when i opened the URL for the testpage i got the following error in the file "hs_err_pid3820" and my webpage displayed a blank page. Can you please help me. It is urgent. # # An unexpected error has been detected by HotSpot Virtual Machine: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x03b31e7b, pid=3820, tid=1824 # # Java VM: Java HotSpot(TM) Client VM (1.5.0_15-b04 mixed mode, sharing) # Problematic frame: # C [php5ts.dll+0xa1e7b] # --------------- T H R E A D --------------- Current thread (0x02f63808): JavaThread "http-8080-Processor25" daemon [_thread_in_native, id=1824] siginfo: ExceptionCode=0xc0000005, reading address 0x0000000a Registers: EAX=0x0000000a, EBX=0x009c1000, ECX=0x009c1000, EDX=0x0000000a ESP=0x0390f3c4, EBP=0x00001505, ESI=0x00138200, EDI=0x009c1000 EIP=0x03b31e7b, EFLAGS=0x00010216 Top of Stack: (sp=0x0390f3c4) 0x0390f3c4: 030ec3f8 009c5054 0000001c 030056f8 0x0390f3d4: 009c1000 03b34e1b 030056f8 0000000a 0x0390f3e4: 009c1000 009c504c 0000003c 0390f424 0x0390f3f4: 00000002 030ec3f8 00000000 02d7a300 0x0390f404: 00000000 02d7a300 00000000 02e05bf0 0x0390f414: 03a983f1 009c2107 009c5010 0000001c 0x0390f424: 02e02f98 009c52e0 030ec3f8 009c4150 0x0390f434: 03f874c0 030ec3f8 03a970f9 00000001 Instructions: (pc=0x03b31e7b) 0x03b31e6b: ff 08 8b df bd 05 15 00 00 72 75 8b f7 c1 ee 03 0x03b31e7b: 0f be 10 8b cd 83 eb 08 c1 e1 05 03 cd 03 ca 40 Stack: [0x038d0000,0x03910000), sp=0x0390f3c4, free space=252k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) C [php5ts.dll+0xa1e7b] [error occurred during error reporting, step 120, id 0xc0000005] Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) j net.php.servlet.startup()V+0 j net.php.servlet.init(Ljavax/servlet/ServletConfig;)V+24 j org.apache.catalina.core.StandardWrapper.loadServlet()Ljavax/servlet/Servlet;+717 j org.apache.catalina.core.StandardWrapper.allocate()Ljavax/servlet/Servlet;+75 j org.apache.catalina.core.StandardWrapperValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+199 j org.apache.catalina.core.StandardContextValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+285 j org.apache.catalina.core.StandardHostValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+64 j org.apache.catalina.valves.ErrorReportValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+6 j org.apache.catalina.core.StandardEngineValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+42 j org.apache.catalina.connector.CoyoteAdapter.service(Lorg/apache/coyote/Request;Lorg/apache/coyote/Response;)V+154 j org.apache.coyote.http11.Http11Processor.process(Ljava/io/InputStream;Ljava/io/OutputStream;)V+611 j org.apache.coyote.http11.Http11
Link / Reply@asha It's a JVM crash. That's always bad news. Try upgrading to a more recent version of Java, this issue may have been patched by Sun. @Kevin & @shorif Do you have an example of PHP code that fails this way? Does it make a difference it you start your scripts with error_reporting(E_ALL)?
Link / ReplyTomcat doesn't seem to fill in the _SERVER variables except for REQUEST_TIME, argv and argc. argv is an empty array. I'd like to get the various kinds of HTTP information such HTTP_USER_AGENT, HTTP_REFERER, etc. Is there anything to do? I prefer using Tomcat.
Link / ReplyI get a ClassNotFoundException on net.php.servlet. What library or jar file is that supposed to be in?
Link / ReplyStep 9 talks about unjarring php5srvlt.jar. In the pecl-5.2.5-win32.zip file I downloaded the name is phpsrvlt.jar. Has anyone gotten the steps to work using this jar file? Just curious why the 2 properties files haven't been updated - the original instructions referred at the top have a date of 12/11/2004. thx!
Link / ReplyI answered my own question (post 8). The ClassNotFoundException I had with net.php.servlet was due to an incorrect re-jarring on my part.
Link / ReplyTry quercus from caucho instead. easier integration, just add the jar in the WEB-INF/lib and you are done.
Link / ReplyOn any nonexisting .php page request Tomcat (actually JVM) fails with error: # An unexpected error has been detected by Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6da22074, pid=3224, tid=3708 # # Java VM: Java HotSpot(TM) Client VM (10.0-b22 mixed mode, sharing windows-x86) # Problematic frame: # V [jvm.dll+0x1b2074] # # An error report file with more information is saved as: # C:\tomcat\bin\hs_err_pid3224.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp Am I the only one with this problem? :)
Link / ReplyHey all! I think I'm messing up the re-jarring of the php5srvlt.jar file. Could someone give me a brief run down on how I'm supposed to do this? I've tried a few different ways but they all keep outputting a "java.lang.ClassNotFoundException: net.php.servlet" error. Cheers. Dan
Link / ReplyAll good, sorted it out. I ended up renaming the php5servlet.dll to php5srvlt.dll and didn't bother rejarring, works a treat. Thanks for the great article.
Link / ReplyCould post a linux version of this guide, and could you be specific about which PECL modules to use? Justin
Link / ReplyMÄÂrtiņš::: It isn't just you. I get the same problem. Request a .php page that doesn't exist and *bang* the JVM crashes and the Tomcat service explodes. (Thankfully windows service recovery options bring the service back up with only 1 min of downtime) I'm still hunting for a way to fix this... it's quite silly that type-o's bring the webserver down.
Link / Replyhi i am getting this error after running php prg.why?after i have configure all HTTP Status 404 - /fun/test.php cofiguratuon: # Go to http://www.php.net/downloads.php and download the current version. I am going to do the setup on a Windows machine here, so I can simply download the binaries. On *nix, you will need to compile PHP. I know I will have to, anyway… # You also need to download the corresponding PECL modules. # Let’s assume that your current Tomcat install can be found in c:\Tomcat5\. Create a c:\Tomcat5\php\ directory and unzip the PHP zip file in it. # Rename php.ini-dist, in c:\Tomcat5\php\, to php.ini # Extract php5servlet.dll from the PECL zip file to c:\Tomcat5\php\ # Create a directory under c:\Tomcat5\webapps\; in our case: phptest # In c:\Tomcat5\webapps\phptest\, create a subdirectory: WEB-INF # In c:\Tomcat5\webapps\phptest\WEB-INF\, create web.xml with the following content: php net.php.servlet php-formatter net.php.formatter php *.php php-formatter *.phps # Extract/unjar (using jar xvf or WinZip) php5srvlt.jar under c:\Tomcat5\php\tmp\ # Modify both c:\Tomcat5\php\tmp\net\reflect.properties and c:\Tomcat5\php\tmp\net\servlet.properties, replacing library=phpsrvlt with library=php5servlet and save. # Jar the content of c:\Tomcat5\php\tmp\ into a new version of php5srvlt.jar # Move php5srvlt.jar to c:\Tomcat5\common\lib\ # Copy c:\Tomcat5\php\php5servlet.dll and c:\Tomcat5\php\php5ts.dll to c:\windows\system32\ # Create a test page in c:\Tomcat5\webapps\phptest\test.php with this contents: Reply plz.....
Link / ReplyOh, man! So easy! What a great post. Shame that some people had trouble with it, but that's often the case with setting up servers and such I guess. I'll have to try this when I get back to it :) One thing I recommend for people having problems is CHECK THE VERSIONS! This article was posted almost a year ago. It may not seem like very long but one little change in either Tomcat or PHP can break the whole procedure, so it's important that the versions people use following your instructions actually match what you did (or close enough). Maybe won't help anybody but always worth checking.
Link / ReplyI am trying to run PHP 5.2.28 on Tomcat 5.5 on Fedora Core4. I also want some way to share session between PHP and Java programs. Please advice.
Link / ReplyHi According to given setup instruction only phpinfo(); is working. When I am trying to execute any other .php file say I want to echo 'Hello World', It is showing blank page.
Link / ReplyHi!. Has anybody resolve the blank page problem?. I`ve try a lot of ways to resolve this but when I open a php page and click on a button.submit() in browser I get a blank page, it´s driving me crazy!!!. For example: in joomla administrator the login page seems to view correctly but when I click on Login button a blank page is displayed. Any idea? Thanks!. Paco.
Link / ReplyI have found this error when you try to run test.php page 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:729) note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs. what the solution, please thanks for help.
Link / Replytest.php work correctly but others *.php not work and don't show anything why?
Link / Reply<a href='#comment-30622' rel="nofollow">@rizeq</a> - So, at first test.php didn't work but then it did, and now other pages are not working? What did you do to 'unglue' test.php? I haven't played with Tomcat + PHP in a while but I would make sure that access rights are similar to that of test.php (of course these settings depend on which version of Windows you are running and I'm not a Windows guru...)
Link / Reply<blockquote><a href='#comment-30621' rel="nofollow">Originally Posted By rizeq</a>I have found this error when you try to run test.php page 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:729) note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs. what the solution, please thanks for help.</blockquote> ------- I have the same problem. Did you solve this problem? If it's true can you help me please?
Link / Reply1. If you see a blank page: Check the page's source code. Does it, by any chance, contain your whole PHP source? If so, make sure that the PHP tags you are using are recognized by Tomcat. 2. UnsatisfiedLinkError: Could be due to looking for your php file in the wrong place. Try moving it from webapps\ to webapps\ROOT\
Link / ReplyI solved the problem! It is needed to move all my pages into ROOT. Thanks Chris!! Now, I'm having some problems with the use functions of PHP. I suppose that is due to extension folder link. I'm fighting with php-java-bridge and I some functions are not detected. eg. request_functions. In phpinfo() I can see that the extensions are includeed.... See you soon.
Link / ReplySorry but im a bit confused. Is it okay to run php 5.x and tomcat 6? Is there any conflict with this?
Link / ReplyHi, I now moved my php files to /ROOT but it displaying blank page. using this code "" in test.php. Any magical advice? Thank you
Link / ReplyIn setting up tomcat5.x and php5.x is there a problem implementing it on windows vista? please help! thanks
Link / ReplyDear all, I'm currently using WAMP to execute php, its workin g well, i want to work in tomcat, can any one explain clearly, wher to download, store and execute php file. thanks to any one.
Link / ReplyHey, I ma getting this error below : 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:118) org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) java.lang.Thread.run(Thread.java:534) root cause java.lang.UnsatisfiedLinkError: C:\WINDOWS\system32\php5srvlt.dll: Can't find dependent libraries java.lang.ClassLoader$NativeLibrary.load(Native Method) java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1586) java.lang.ClassLoader.loadLibrary(ClassLoader.java:1511) java.lang.Runtime.loadLibrary0(Runtime.java:788) java.lang.System.loadLibrary(System.java:834) 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:118) org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) java.lang.Thread.run(Thread.java:534) note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
Link / ReplyDr_Watson or others, Has anyone got a solution for the Tomcat crash when you access a PHP page that doesn't exist?
Link / Replycan anyone tell,which file are download for given download link? please help me.
Link / ReplyThis guide was for PHP5.2.5 but you could download any 5.x version.
Link / Replynice try, mr. Ravenscroft, but it seems to crash for 99% of the people. You should be more rigourous with your tests. Regards.
Link / ReplyHi, thanks for your input. This method more or less worked in February of 2008. There were of course cases where it didn't work because it was, after all, a hack. I certainly do not expect something written three years ago -- again, a hack -- to hold any water today! -C.
Link / Replytest.php work correctly but others *.php not work and don’t show anything.. and write the output to stderr.txt file..?..
Link / ReplyGilbert, I just edited the top of this post with more current resources. I apologize for now doing this earlier. -Chris.
Link / ReplyGreat post, but it seems like you are missing the "\" marks in your directory examples. You keep referencing: c:Tomcat5php c:Tomcat5webappsphptest Took me a while to figure out you are trying to say: c:\Tomcat5\php c:\Tomcat5\webapps\phptest
Link / Reply[...] The Nexus » How To Setup PHP5 with Tomcat 5Feb 15, 2008 … I was successful setting up php5.2.5 / tomcat5.5 on windows xp. One small suggestion is ….. Is it okay to run php 5.x and tomcat 6? Is there any … [...]
Link / Replyhow did u solved this pls explain., how to do unjaring and jaring exactly
Link / Replyfollowed the steps very carefully but when i go to my address, i am having this exception 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: net.php.servlet.send(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Z)V 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:729) note The full stack trace of the root cause is available in the Apache Tomcat/5.5.35 logs. Apache Tomcat/5.5.35 any way to resolve it???
Link / ReplyComment awaiting approval 2 weeks, 4 days ago
Comment deleted 11 months, 1 week ago
New Comment