Thursday, May 12, 2011

PHP on tomcat6 in ubuntu /Linux

Came across a need where we needed to install PHP on tomcat6 on ubuntu.
After many unsuccessful attempts was able to finally get it going
Here are the steps I followed
1. install php5 on unbuntu sudo apt-get install php5
2. install tomcat on ubuntu
3. install php-cgi sudo apt-get install php5-cgi
4. install php-gd sudo apt-get insatall php5-gd

Once this is done
download the JavaBridge.jar , php-script.jar , php-servlet.jar . These are easily available on sourceforge.net .

Copy all these jars in the %tomcat%/lib folder.
change the %tomcat%/conf web.xml for the php java an php servlet ampping

-- these are the mapping for enabling the php on tomcat--
<listener>
<listener-class>php.java.servlet.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>PhpJavaServlet</servlet-name>
<servlet-class>php.java.servlet.PhpJavaServlet</servlet-class>
</servlet>

<servlet>
<servlet-name>PhpCGIServlet</servlet-name>
<servlet-class>php.java.servlet.fastcgi.FastCGIServlet</servlet-class>
<init-param>
<param-name>prefer_system_php_exec</param-name><param-value>On</param-value></init-param>
<init-param>
<param-name>php_include_java</param-name><param-value>Off</param-value></init-param>
</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>

restart your tomcat.. and this should be it...
shoot me any questions if you have any

No comments: