Thursday, May 1, 2008

Executing Perl/CGI Scripts in JBoss [JBoss Web] ராம்குமார்

In case if you are using any Perl/CGI application in JBOSS AS [Application Server] its pretty Cool to do this in JBOSS AS. Lets see how to Configure Perl/CGI in JBOSS AS.

Goto web.xml of your server by going to the location as $JBOSS_HOME/server/<your-server>/deploy/jboss-web.deployer/conf/web.xml file.

On there you Just Uncomment the <servlet> and <servlet-mapping> for the servlet name cgi, ie you want to uncomment



<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>

and

<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
then get back a directory means navigate to $JBOSS_HOME/server/<your-server>/deploy/jboss-web.deployer/ directory there you can find context.xml file on there you add the privileged="true" on the root tag itself like,

<Context cookies="true" crossContext="true" privileged="true">.

Then copy the <servlet> and <servlet-mapping> tags to your web.xml in your web Application. But you must change the servlet name cgi to someother.

Goto WEB-INF folder in your application and create a directory called "cgi" put all your perl files in this directory with the extension of .cgi Restart the server.

Now Try to execute your CGI files in the browser.


NOTE
:
  • You must need to edit the context.xml and set the previleged="true" if not you'll get some security exceptions.
  • Also in your web.xmlin your Appliction you need to change the servlet name cgi to some other else it throws JNDI exception because the cgi is already exsists due to web.xml in the server.

Executing PHP Scripts in JBOSS [JBoss-web] ராம்குமார்

In case if you are using any PHP application in JBOSS AS [Application Server] no need for installing specially PHP Engine into your machine, you just configure jboss.web services in JBOSS AS in enough. Lets see how to Configure PHP in JBOSS AS.

Download the jbossweb-extras.jar using following URL
http://anonsvn.jboss.org/repos/jbossreflex/trunk/php/jbossweb-extras.jar

This jar file contains the Listeners for the PHP, move this jar file to $JBOSS_HOME/server/<your_server>/deploy/jboss-web.deployer directory.
[ JBOSS_HOME in the sense that Location of your Jboss ex: /usr/jboss-4.2.0.GA in Linux].

In the same Location get the server.xml file and edit it, add the following Listener code to that file <Listener classname="org.jboss.web.php.LifecycleListener"/>

Then move to $JBOSS_HOME/server//deploy/conf directory and edit the web.xml file and add the following codes in order to make URL pattern mapping


<servlet>
<servlet-name>php</servlet-name>
<servlet-class>org.jboss.web.php.Handler</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>6</load-on-startup>
</servlet>
<servlet>
<servlet-name>phps</servlet-name>
<servlet-class>org.jboss.web.php.Highlight</servlet-class>
</servlet>

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



Then download the .so [Shared Object] files for PHP in order make PHP as servlet from the following URL,

http://download.jboss.com/jbossweb/modules/php/php5servlet-linux-i686-1.0.2.tar.gz

Uncompress it,

]# tar -zxf php5servlet-linux-i686-1.0.2.tar.gz

So you will get php5servlet-linux-i686-1.0.2 directory contains a single directory named PHP. we are going to map this directory to JBOSS AS so for naming convention make “php5servlet-linux-i686-1.0.2/PHP” as “PHP” by using

]# mv php5servlet-linux-i686-1.0.2/PHP PHP

Now you have the location of this PHP directory which contains *.so files. Goto $JBOSS_HOME/bin directory and edit run.conf file and add the following lines to set the library path for the downloaded *.so files.
LD_LIBRARY_PATH=/PHP/lib
export LD_LIBRARY_PATH

Restart your server now and make execute your php files.

NOTE:
Regards,
M.Ramkumar[ராம்குமார்]