Feb 17 2008

Installing GlassFish v2 with PHP5 on Port 80

Published by Siegfried Bolz at 2:41 am under GlassFish, Linux

Welcome to my first blog entry. It’s about installing GlassFish v2 on Opensuse 10.1 with support for PHP5 and running on Port 80.

Note:
Download-links to all files are available at the end of this posting.

Install Java
First you need an installed Java SE Development Kit. I prefer the current version 6. Download JDK6 from: http://java.sun.com/javase/downloads/?intcmp=1281

Opensuse has very old versions in its repository. You can uninstall it using yast or if you have a virtual server, using plesk or confixx.
To check which version is currently installed, open a shell and run the command: java -version.

I will now continue with the installation of a brand new JDK. After you have downloaded the new JDK, switch to the directory and make it runable:

chmod 777 jdk-6u4-linux-i586.bin”

Now start the file:

./jdk-6u4-linux-i586.bin”

Java Installation1

You see a License Agreement. Press Q and type yes to agree to the license. Now your JDK is unpacking. After this operation, move the new JDK-folder to /opt

Java Installation2

Now change to /usr/lib/jvm
Run: ln -s /opt/jdk-6u4-linux-i586 java

Next, you will have to create an environment variable.
Edit the file /etc/profile

I recommend to use the midnight commander. Open the file and search for export PATH. After this line, insert:

JAVA_HOME="/usr/lib/jvm/java"
export JAVA_HOME
PATH="$PATH:/usr/lib/jvm/java/bin"
export PATH

Java Installation3

To check if everything is alright, type java -version.

Java Installation4


Install GlassFish2
Ok, first step is finished, now let’s go to the second step - installing GlassFish2!

Download Glassfish here: https://glassfish.dev.java.net/
Give it the needed rights:
chmod 777 glassfish-installer-v2ur1-b09d-linux.jar

and start the installer:
java -Xmx256m -jar glassfish-installer-v2ur1-b09d-linux.jar

You will see a license message. If you are using KDE or Gnome, watch for a small window popup.
When the unpacking is finished, change to the created directory: cd glassfish

Run: ./lib/ant/bin/ant -f setup.xml

If you have errors, uninstall any existing ANT-versions. GlassFish2 is delievered with an own ANT-version.
So, installation of GlassFish2 is nearly finished. You can start GlassFish2 with the command:

./bin/asadmin start-domain domain1

GlassFish2 - First blood

and stop it with:

./bin/asadmin stop-domain domain1

To see the Glassfish2 Testpage, just browse to:

http://localhost:8080
GlassFish2 - running

To access the Server Admin Console, browse to:

http://localhost:4848

Change Port from 8080 to 80
Login to the Server Admin Console
http://localhost:4848

User Name: admin
Password: adminadmin

Navigate to:

Configuration->HTTP Service->HTTP Listeners->http-listener-1

change the Listener Port from 8080 to 80.

Shutdown Glassfish2 and restart it. That’s it!

GlassFish2 - Server Admin Console



Install PHP5 Support

Download Qercus 3.1.3 Binary from: http://quercus.caucho.com/
Extract the included JAR’s (quercus.jar, resin-util.jar, script-10.jar)
and move them to: /opt/glassfish/domains/domain1/lib/
Location of Quercus jars

Now create a test-application with your favourite IDE. I prefer Netbeans 6. You need a special WEB.XML :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5">
  <description>Caucho Technology's PHP Implementation, Running on GlassFish Java EE 5</description>
  <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.php</welcome-file>
  </welcome-file-list>
</web-app>

Netbeans 6 - hellophp

Deploy the WAR in the Server Admin Console. Navigate to: Applications->Web Applications->Deploy

Deploy hellophp

Finished!

Hellophp running


Downloads
Hellophp sample application: download
Quercus libs: download

Technorati Tags: , , , , ,


17 Responses to “Installing GlassFish v2 with PHP5 on Port 80”

  1. maryon 29 Feb 2008 at 9:49 pm

    Very nice tutorial, and blog! Even though I am not a Java programmer(yet), you have some excellent posts and tutorials here! I’m actually going to try this one out! Thanks!

    mary

  2. [...] first entry shows how to run GlassFish v2 with Quercus (i.e. PHP5) on OpenSUSE 10.1. Given the earlier news on Frank and Ted, this seemed [...]

  3. [...] 10.1 上で GlassFish v2 と Quercus (i.e. PHP5) [...]

  4. [...] 처음 엔트리는 GlassFish v2 와 Quercus를 (예를 들어 PHP5)  OpenSUSE 10.1에서 실행하는 방법에 관한 것입니다. Frank [...]

  5. [...] GlassFish v2 与 Quercus (i.e. PHP5) 在 OpenSUSE 10.1上. 给一些更早些的新闻在Frank 和 Ted上, [...]

  6. Thorleif Wiikon 10 Mar 2008 at 11:46 pm

    Did you try to install some common PHP apps, e.g. Wordpress ?

  7. Siegfried Bolzon 11 Mar 2008 at 8:39 am

    I tried only my own PHP-Webpages. When i have time, i will write a blog-entry about using GlassFish with common PHP apps.

  8. Namon 19 Mar 2008 at 6:58 pm

    Quercus should work with Wordpress, Mediawiki, and Drupal.

  9. Ganeswar mishraon 03 May 2008 at 1:48 pm

    Sir I don’t know from the above para that how could I install php in Glass Fish with jdk-6

  10. annaon 03 May 2008 at 1:51 pm

    It is very useful to us and think that it would be use ful to other

  11. Siegfried Bolzon 03 May 2008 at 2:25 pm

    Hello Ganeswar,
    first extract the quercus-jar files into the GlassFish-directory and than try to run my example. You can download all files from the “Download”-section of this blog.

  12. Dannyon 24 Jul 2008 at 3:05 pm

    Hey, great tutorial, but you forgot the m in your java -Xmx256 -jar glassfish_installer line. should be like java -Xmx256m -jar glassfish_installer….

  13. Siegfried Bolzon 24 Jul 2008 at 8:18 pm

    Hello Danny,
    thank you for this special note, i have updated this blog. Without the “m” you will get this error:

    Exception in thread “main” java.lang.OutOfMemoryError: Java heap space

  14. Brad Lanieron 02 Aug 2008 at 3:45 am

    WOW! This is great. The download links seem to be broken….any chance of fixing that?

    Thanks,
    Brad

  15. Siegfried Bolzon 02 Aug 2008 at 8:34 pm

    Thanks for the info Brad, i have fixed the downloads!

  16. msaifon 14 Aug 2008 at 6:37 am

    I have one question .

    Now with Qercus 3.1.3 Java library, is PHP file converted into Java bytecode file that is *.class file?
    Is converted Java Bytecode executed on JRE?

    Second is I am using Zend Framework 1.5 library with Apache server.Now I am rethinking about my system with GlassFish server because i am java programmer.Then if I put Qercus 3.1.3 Java library and Zend library 1.5(zip file) and mysql_pdo.so(shared object file ) in glass fish library directory then will Zend Framework run correctly? or any other suggestion?

    Pls help me .

  17. hron84on 25 Oct 2009 at 7:56 am

    There is a big bug in article, the servlet-name _must_ be QuercusServlet - without a space! - or glassfish will die. Tested with GlassFish v2.1

    Anyway, i got heap space exception too… so i using java-php-bridge.

Trackback URI | Comments RSS

Leave a Reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image

Note: To submit your comment you have to preview it at first!