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 Download -
download 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
directory -
copy
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 addedC:\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 Computer -
create
test.php
for testing undertomcat\webapps\php
like -
Restart tomcat
-
browse
localhost:8080/php/test.php