Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a php app using tomcat?

Tags:

php

apache

tomcat

Is it possible to run a PHP app using tomcat?

Before you tell me to just use httpd, I already have a Java application running on my webserver at host/myapp. Now I want to install RoundCube at host/roundcube.

One is PHP and one is Java. I keep seeing offhand references saying this is possible but no real instructions. I do not want to put them on separate ports, I need the standard HTTP and HTTPS ports.

Does anyone have any resources for this?

like image 817
GBa Avatar asked Apr 22 '09 21:04

GBa


People also ask

Can I run php on Tomcat?

For running php scripts you have to install php on your machine. Then deploy the war file into tomcat webapps folder and start the server. It will create a directory in webapps named as the war file name. Then you can put your php scripts or php project into that directory and restart the tomcat server.

How do I run a php file?

php” file is placed inside the “htdocs” folder. If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.


1 Answers

Yes it is Possible Will Den. we can run PHP code in tomcat server using it's own port number localhost:8080

here I'm writing some step which is so much useful for you.

How to install or run PHP on Tomcat 6 in windows

  1. download and unzip PHP 5 to a directory, c:\php-5.2.6-Win32 - php-5.2.9-2-Win32.zip Download

  2. download PECL 5.2.5 Win32 binaries - PECL 5.2.5 Win32 Download

  3. rename php.ini-dist to php.ini in c:\php-5.2.6-Win32

  4. Uncomment or add the line (remove semi-colon at the beginning) in php.ini: ;extension=php_java.dll

  5. copy php5servlet.dll from PECL 5.2.5 to c:\php-5.2.6-Win32

  6. copy php_java.dll from PECL 5.2.5 to c:\php-5.2.6-Win32\ext

  7. copy php_java.jar from PECL 5.2.5 to tomcat\lib

  8. create a directory named "php" (or what ever u like) in tomcat\webapps directory

  9. copy phpsrvlt.jar from PECL 5.2.5 to tomcat\webapps\php\WEB-INF\lib

  10. Unjar or unzip phpsrvlt.jar for unzip use winrar or winzip for unjar use : jar xfv phpsrvlt.jar

  11. change both net\php\reflect.properties and net\php\servlet.properties to library=php5servlet

  12. Recreate the jar file -> jar cvf php5srvlt.jar net/php/. PS: if the jar file doesnt run you have to add the Path to system variables for me I added C:\Program Files\Java\jdk1.6.0\bin; to System variables/Path

  13. create web.xml in tomcat\webapps\php\WEB-INF with this content:

    <web-app version="2.4"    xmlns="http://java.sun.com/xml/ns/j2ee"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">   <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> 
  14. Add PHP path( c:\php-5.2.6-Win32) to your System or User Path in Windows enironment (Hint: Right-click and select Properties from My Computer

  15. create test.php for testing under tomcat\webapps\php like

  16. Restart tomcat

  17. browse localhost:8080/php/test.php

like image 52
Saunik Singh Avatar answered Sep 19 '22 23:09

Saunik Singh