Tuesday, February 7, 2017

PHP In GlassFish

PHP In GlassFish


GlassFish is an App Server written in Java. So GlassFish does most of its work with the help of Java Servlets.

GlassFish does not have built-in support for PHP. Actually it can support PHP if a Java implementation of PHP exists for GlassFish. This was made available by Quercus Caucho at http://quercus.caucho.com/. Download the binaries and source of Quercus from the site.

Assuming that GlassFish is installed and its directory path is represented as "glassfish", proceed with the following steps -

  • Extract the contents of the archive downloaded from the Quercus Caucho website
  • Copy quercus.jar, resin-util.jar and script-10.jar from the WEB-INF/lib directory which is obtained from extracting the zip file to glassfish/lib directory
  • Open the file glassfish/domains/domain1/config/default-web.xml and add the following lines

<servlet>
<servlet-name>Quercus Servlet</servlet-name>
<servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
<init-param>
<param-name>ini-file</param-name>
<param-value>WEB-INF/php.ini</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>Quercus Servlet</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>

  • The first set of configuration indicates that there is a servlet available under the name Quercus Servlet and the second set of configuration indicates that the servlet is to be run whenever a file with php extension is encountered

That’s it, restart GlassFish and it should be now be compatible to understand PHP.


Available link for download