Run a php app using tomcat?
Solution 1:
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
download and unzip PHP 5 to a directory,
c:\php-5.2.6-Win32
- php-5.2.9-2-Win32.zip Downloaddownload PECL 5.2.5 Win32 binaries - PECL 5.2.5 Win32 Download
rename
php.ini-dist
tophp.ini
inc:\php-5.2.6-Win32
Uncomment or add the line (remove semi-colon at the beginning) in
php.ini
:;extension=php_java.dll
copy
php5servlet.dll
from PECL 5.2.5 toc:\php-5.2.6-Win32
copy
php_java.dll
from PECL 5.2.5 toc:\php-5.2.6-Win32\ext
copy
php_java.jar
from PECL 5.2.5 totomcat\lib
create a directory named
"php"
(or what ever u like) intomcat\webapps
directorycopy
phpsrvlt.jar
from PECL 5.2.5 totomcat\webapps\php\WEB-INF\lib
Unjar or unzip
phpsrvlt.jar
for unzip use winrar or winzip for unjar use :jar xfv phpsrvlt.jar
change both
net\php\reflect.properties
andnet\php\servlet.properties
tolibrary=php5servlet
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
-
create
web.xml
intomcat\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>
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 Computercreate
test.php
for testing undertomcat\webapps\php
likeRestart tomcat
browse
localhost:8080/php/test.php
Solution 2:
It's quite common to run Tomcat behind Apache. In Apache you can then direct certain URLs to Tomcat, and have Apache/PHP handle the others (including the static images).
(On Unix, Tomcat itself cannot securely made to run on port 80, while Apache can. Tomcat, being a Java process, would be required to run as root, while Apache will switch to non-root privileges as soon as port 80 has been claimed. So, running Apache on port 80 and have it redirect some or all requests to Tomcat, is quite common on Unix.)
Solution 3:
Caucho Quercus can run PHP code on the jvm.