PHP in GlassFish using Caucho Quercus
Quercus is
Caucho Technology's 100% Java implementation of
PHP 5. Ludo
described the steps to deploy PHP web applications on
GlassFish. Caucho has released a new
version of Quercus since then. This blog
entry is an update to the
steps described earlier.
- First, PHP-enable GlassFish.
- Unjar
quercus-3.1.1.war and copy the JAR files in "WEB-INF/lib"
directory to "GLASSFISH_HOME/domains/domain/lib" directory. That's it!
Although the original entry requires to copy the JARs in "GLASSFISH_HOME/lib/addons"
directory but that
didn't work.
- Unjar
- Create a PHP web application
- Create a new Web application project, lets say "
hellophp",
using NetBeans IDE and choose
GlassFish as the server. - Replace the contents of "web.xml" with the following fragment:
<samp><?xml version="1.0" encoding="UTF-8"?><br>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"<br>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br>
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"<br>
version="2.5"> <br>
<description>Caucho Technology's PHP Implementation, Running on GlassFish
Java EE 5</description> <br>
<servlet><br>
<servlet-name>Quercus Servlet</servlet-name><br>
<servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class><br>
</servlet> <br>
<servlet-mapping><br>
<servlet-name>Quercus Servlet</servlet-name><br>
<url-pattern>*.php</url-pattern><br>
</servlet-mapping> <br>
<welcome-file-list><br>
<welcome-file>index.php</welcome-file><br>
</welcome-file-list><br>
</web-app></samp>
This will declare PHP engine as the servlet. - Add a new page "
index.php" in "Web pages"
folder. The contents of the page are:
This page prints "Hello World!" on the browser and some<?php<br>
echo "Hello World!";<br>
phpinfo();<br>
?><br>
<br>
configuration settings of PHP. The directory structure of the created project looks like:
Notice, "META-INF/<br>
META-INF/MANIFEST.MF<br>
WEB-INF/<br>
WEB-INF/classes/<br>
WEB-INF/sun-web.xml<br>
WEB-INF/web.xml<br>
index.jsp<br>
index.php<br>
<br>
index.jsp" is only a template
file to get started with JSPs and "sun-web.xml"
is GlassFish-specific deployment descriptor. These files are
not required for this PHP application although it does not hurt to leave
them in the webapp as well.
- Create a new Web application project, lets say "
- Deploy the application by right-clicking on the project and selecting "
". Your first PHP application in GlassFish is now deployed atDeploy
Project
"http://localhost:8080/hellophp/index.php".
Now that you have verified that your GlassFish is ready to host PHP
applications, try the different applications that are described in
Ludo's blog.
Technorati:
php
glassfish
caucho
quercus
- Login or register to post comments
- Printer-friendly version
- arungupta's blog
- 7074 reads






Comments
Thanks!
by garryd - 2010-04-26 19:30
Great tutorial - I've tried this with the latest Glassfish and Quercus which seems to work very well. I also went with a slightly different configuration so I wouldn't have to encase the php files in a war. The details for this are posted here: How to PHP enable your Glassfish Application Server -GarryThanks!
by ucsd5 - 2010-12-15 15:32
What parameter is http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd in line 4 of the code? I'm not sure if I just need to read more about the syntax altogether or what, but that doesn't seem to have a parameter label on it.