Running Quercus in Jetty Web Server
Jetty Web server can be invoked and installed as a stand alone application server. It has a flexible component based architecture that allows it to be easily deployed and integrated in a diverse range of instances. The project is supported by a growing community and a team with a history of being responsive to innovations and changing requirements. More info here.
Installing Jetty
First you need to download Jetty. It’s distributed as a platform independent zip file containing source, javadocs and binaries. The most recent distro can be downloaded from Codehaus:
$ wget http://dist.codehaus.org/jetty/jetty-6.1.14/jetty-6.1.14.zip $ unzip jetty-6.1.14.zip $ cp -R jetty-6.1.14 /opt/ $ cd /opt $ ln -s /opt/jetty-6.1.14 jetty
Problems installing Jetty? More info here.
Running Jetty
Running jetty is as simple as going to your jetty installation directory and typing:
$ cd /opt/jetty $ java -jar start.jar etc/jetty.xml
This will start jetty and deploy a demo application available at:
http://localhost:8080/test
That’s it. Now stop Jetty with cntrl-c in the same terminal window as you started it.
Installing Quercus
Quercus is a complete implementation of the PHP language and libraries in Java. It gives both Java and PHP developers a fast, safe, and powerful alternative to the standard PHP interpreter. Quercus is available for download as a WAR file which can be easily deployed on Jetty:
$ wget -P ~/quercus http://quercus.caucho.com/download/quercus-3.2.1.war $ jar xf ~/quercus/quercus-3.2.1.war
Unpack the WAR file and copy all the jars to Jetty’s global library directory:
$ cp ~/quercus/WEB-INF/lib/* /opt/jetty/lib
Configuring Jetty
Edit the web.xml file:
$ vi /opt/jetty/webapps/test/WEB-INF/web.xml
Add the following between the web-app tags:
<servlet>
<servlet-name>Quercus Servlet</servlet-name>
<servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Quercus Servlet</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.php</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Create a PHP file inside the test application:
$ cat /opt/jetty/webapps/test/index.php <?php phpinfo(); ?>
This file will be available at:
http://localhost:8080/index.php
It works! You are now ready to:
Instantiate objects by class name
<?php
$a = new Java("java.util.Date", 123);
print $a->time;
Import classes
<?php import java.util.Date; $a = new Date(123); print $a->time;
Call Java methods
<?php import java.util.Date; $a = new Date(123); print $a->getTime(); print $a->setTime(456); print $a->time; $a->time = 456;
And much, much more.
[...] Running PHP with Quercus in Jetty Web Server () [...]
vivanno.com
January 5, 2009 at 5:40 pm
[...] your languages together, you’re going to love this one: Federico Cargnelutti has posted an article about running your PHP programs under Quercus, a “100% Java implementation of PHP”, and [...]
PHP, Java and Jetty | The Desi Video Blog
January 22, 2009 at 3:15 am
What about the performance. Did you do any benchmark ?
MgX
January 23, 2009 at 1:45 pm
Hi,
These directions are great! However, I followed these directions, and I keep getting an ERROR/404 when trying to display php files. Why doesn’t Quercus recognize the php files?
thanks.
Cindy
January 24, 2009 at 2:49 am
@MgX
Benchmarks against PHP 5.2 with APC here: http://forum.caucho.com/?q=node/6
@Cindy
Forum and support http://forum.caucho.com/?q=forum/2
Federico
January 24, 2009 at 11:17 am
I tried the directions again today, and it worked perfectly! Thanks for the great directions. Please disregard the previous message.
Cindy
January 24, 2009 at 4:41 pm
I have been looking to give Quercus a spin for a while now, this howto will get me going, thanks!
Robert Brainstorm
February 3, 2009 at 5:39 pm
I have set up Quercus over Tomcat and when I tried to run Dokuwiki (written in PHP) it came up with some bugs. Quercus is not a complete implementation of PHP.
Michel
February 26, 2009 at 4:45 am
I couldn’t get this working in Jetty for the life of me with these directions. HOWEVER, if I just add the and sections to the etc/webdefault.xml file, it works flawlessly.
Hope this helps someone.
Phil Andrews
March 18, 2009 at 11:06 pm
[...] how to run PHP with Quercus in Jetty Web Server. Posted by Federico Filed in Java, PHP, Programming No Comments [...]
PHP Support in Google App Engine « fede.carg ( blog )
April 13, 2009 at 10:43 pm
Is it possible to run CodeIgniter through Quercus?
Amit Kaushik
April 14, 2009 at 2:15 pm
work perfectly, great post, great QUERCUS !
alessio
May 19, 2009 at 4:36 pm
If you experience problems with running certain PHP 5 application with Quercus, it my not be a PHP issue at all. This is true for running these same applications on IIS. It seems that some things require the use of APACHE Web server. This is what happens when you start to write code that is dependent upon a specific webserver or Operating System. It’s simply the fact that the PHP application is not written as portable code.
Chaz Scholton
June 6, 2009 at 10:02 pm
Thanks mate for this post. I am running Quercus inside Jetty inside Grails. I can share some variables and session id between Grails and PHP! Plus, I have PHP as a tool inside my Grails web apps.
Unfortunately Quercus is not always compatible with all PHP code, but I think it perfet for integrating Java and PHP. For Java we should think about Jython, JRuby, Groovy, Scala, Clojure…
I think that the JVM can become a fantastic common execution environment, something like Parrot.
Riccardo
June 26, 2009 at 4:18 pm
Any reason why this doesn’t work with jetty 7?
Sal
December 11, 2009 at 8:35 am
[...] Learn how to run PHP with Quercus in Jetty Web Server. [...]
PHP Support in Google App Engine « UR-Technology
March 7, 2010 at 2:26 am
By far the most up to date information I found on this topic.Thanks
Marquis Paco
May 14, 2010 at 7:45 pm
Jetty runs on Android, so You san develop php web appliactions served from localhost.that means tons of App expertise and programmers can enter The platform… please write again about this topic
devsmt
December 28, 2011 at 3:59 pm