0

i want to run single php file using apache-tomcat-6.0.18

my project is GWT project with server side is java servlet

i deployed my project on server in apache-tomcat-6.0.18/webapps/ folder

So please tell me the solution to run php file

Tushar Ahirrao
  • 12,669
  • 17
  • 64
  • 96
  • 3
    Tomcat is designed for running servlets, which handle their own responses to HTTP requests. PHP is designed as a preprocessor that runs in tandem with a full-blown webserver like Apache, which handles the requests itself. – Amber Apr 13 '10 at 08:53
  • Agree with Dav. You are mixing things up. Its possible to run PHP from within java (as explained in a post below), but you want to stay away from it. Either run java servlets, or completely run PHP as explained in http://code.google.com/p/gwtphp/ if you absolutely want GWT as well. But don't mix technologies, its not worth it. – Sripathi Krishnan Apr 13 '10 at 10:38

5 Answers5

2

We can do this by using JavaBridge..

Download below jar file (ie extract jars from JavaBridge.war)

JavaBridge.jar
php-script.jar
php-servlet.jar

and put into your project lib folder. then type the following entry in web.xml

web.xml

<!-- the following 8 lines extend the servlet spec 2.2 "url-pattern" to handle PHP PATH_INFO: *.php/something?what=that. Remove them, if you don't need this feature. -->
    <filter>
        <filter-name>PhpCGIFilter</filter-name>
        <filter-class>php.java.servlet.PhpCGIFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>PhpCGIFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- the following adds the JSR223 listener. Remove it if you don't want to use the JSR223 API -->
    <listener>
        <listener-class>php.java.servlet.ContextLoaderListener</listener-class>
    </listener>

    <!-- the back end for external (console, Apache/IIS-) PHP scripts; remove it if you don't need this -->
    <servlet>
        <servlet-name>PhpJavaServlet</servlet-name>
        <servlet-class>php.java.servlet.PhpJavaServlet</servlet-class>
    </servlet>

    <!-- runs PHP scripts in this web app; remove it if you don't need this -->
    <servlet>
        <servlet-name>PhpCGIServlet</servlet-name>
        <servlet-class>php.java.servlet.fastcgi.FastCGIServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>


    <servlet-mapping>
        <servlet-name>PhpJavaServlet</servlet-name>
        <url-pattern>*.phpjavabridge</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>PhpCGIServlet</servlet-name>
        <url-pattern>*.php</url-pattern>
    </servlet-mapping>

save the file. Restart tomcat server. now Php files will be work under tomcat server!

j0k
  • 22,600
  • 28
  • 79
  • 90
Pugal
  • 21
  • 4
2

"www" folder is present in IIS server not in apache ... In apache tomcat server instead of "www" , "Root" folder is present copy all those needed files in that root folder and have acces to thos files

after installation of any server a single restart is mandatory ,, otherwise results are unpredictable... Thanks a lot

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Prashant
  • 21
  • 1
1

Use the PHP/Java Bridge. As long as your PHP was compiled with cgi support, it should work seamlessly.

0

Quercus has a war that allows to run PHP scripts in apache tomcat or glassfish. For a step by step guide look at this article

-1

You should put your php file in www folder in apache installation and then you can access that file from browser like this:

http://localhost/your_file_name.php

localhost is the default host name in most configurations.

Sarfraz
  • 377,238
  • 77
  • 533
  • 578