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?
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.
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.
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
to php.ini
in c:\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 to c:\php-5.2.6-Win32
copy php_java.dll
from PECL 5.2.5 to c:\php-5.2.6-Win32\ext
copy php_java.jar
from PECL 5.2.5 to tomcat\lib
create a directory named "php"
(or what ever u like) in tomcat\webapps
directory
copy phpsrvlt.jar
from PECL 5.2.5 to tomcat\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
and net\php\servlet.properties
to library=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
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>
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 under tomcat\webapps\php
like
Restart tomcat
browse localhost:8080/php/test.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With