Showing posts with label Java-bridge with PHP 5.2 apache linux. Show all posts
Showing posts with label Java-bridge with PHP 5.2 apache linux. Show all posts

Friday, October 19, 2007

configuring and installing Mod_perl with apache

Requirement

  1. mod_perl-2.0.3.tar.gz
  2. Assuming apache2 is installed

Operating system
  1. Linux
  2. I am using Fedora core 5 but these steps should work fine for most of the linux systems

Installing mod_perl

tar -xvzf mod_perl-2.0.3.tar.gz
cd mod_perl-2.0.3

run
# which apxs

if its not found then do a

#yum nstall httpd-devel ;# works on FC

for others get a compatible version of your httpd-devel and install it
as apxs gives the information required to build the mod_perl.so module.

do a
#which apxs
again to check where its installed

Assuming that its installed in /usr/bin/apxs

Run

#perl MakeFile.PL MP_APXS=/usr/bin/apxs
#make
#make test
#make install

this would install all the modules required to run mod_perl in the PERL5LIB path


Copy the mod_perl.so to your <>/modules /etc/httpd/modules/

Edit your httpd.conf and add


LoadModule perl_module modules/mod_perl.so


And now restart your server.

Testing the mod_perl module.

create a /var/www/html/perl/rock.pl

print "Content-type: text/html\n\n";
print "mod perl rocks";
print "

test

";




Edit your httpd.conf and add the following

Alias /perl/
/var/www/html/perl/
<Location /perl/>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
Order allow,deny
Allow from all
</Location>

Try to access from your browser

http://localhost/perl/rocks.pl

Using a module to handle a request

create a file Hello.pm and make sure the path exists in @INC
to check the @INC paths
perl -e 'print join("\n",@INC)'

type the following in


package Hello;
use Apache2::RequestRec();
use Apache2::RequestIO();
use Apache2::Const -compile=>qw(OK);

sub handler{
my $r=shift;
$r->content_type('text/html');
print 'welcome';
return Apache2::Const::OK;
}
1;


edit your httpd.conf and add

PerlModule Hello

SetHandler perl-script
PerlResponseHandler Hello
PerlSendHeader On


Use a browser now and try the URL
http://localhost/HI


Useful links

http://www.perl.com/pub/a/2002/02/26/whatismodperl.html
http://www.revsys.com/writings/modperl.html

Thursday, October 18, 2007

Java-bridge with PHP 5.2

Configuring JavaBridge on PHP 5.2 and Apache on Linux


  1. jdk-6u5-ea-bin-b04-linux-i586-27_sep_2007.bin
  2. php-java-bridge_4.3.0_j2ee.zip
  3. Apache/2.0.54
  4. PHP 5.2

Steps to install Java on Linux

  1. Untar jdk-6u5-ea-bin-b04-linux-i586-27_sep_2007.bin
  2. Copy it to /var
  3. So you should now have a /var/jdk1.6.0_05/
  4. Edit /etc/profile and ~/.bash_profile and add
  5. PATH=$PATH:/var/jdk1.6.0_05/bin
  6. CLASSPATH=/var/jdk1.6.0_05/lib:.:/opt/java_classes
  7. export PATH CLASSPATH

Restart the system for the environment to take effect or just relogin to get the setting on your env

Do an env and you should now see the path and CLASSPATH variable pointing to /var/jdk1.6.0_05/

Test java the installation by

$ java –version
java version "1.6.0_05-ea"
Java(TM) SE Runtime Environment (build 1.6.0_05-ea-b04)
Java HotSpot(TM) Client VM (build 1.6.0_05-ea-b04, mixed mode, sharing)


Installing PHP-Java-Bridge

·

  1. unzip php-java-bridge_4.3.0_j2ee.zip
  2. run test.sh
  3. this will create all the files
  4. if you do a ps –ef you will see a process like
  5. /var/jdk1.6.0_05/jre/bin/java -jar /root/java-bridge/tmp/ext/JavaBridge.jar SERVLET_LOCAL:8080
  6. This means the server is started fine
  7. copy the jars to java classpath
  8. copy ext/* /var/jdk1.6.0_05/lib/

Testing your installation

Creating a java class

cd /opt/java_classes

Create a new Java File PHP_BRIDGE.java

//begin

public class PHP_BRIDGE{
public String show(String str){
return "Test"+str;

}
public static void main(String[] args){

}

}

#javac PHP_BRIDGE.java


Create a php file to access java class/methods


cd /var/www/html
create a new php file
#file : test.php

require_once('/tvus/vista/jb/java/Java.inc'); @java_reset(); java_require('/opt/java_classes/'); $obj1=new Java(‘PHP_BRIDGE’); echo $obj1->show('this is me'); @java_reset(); ?>

From command line try to run the same

#php-cgi test.php
#jrunscript –l php test.php

Try from your web browser to access the script

http://localhost/test.php


"If both these work fine then you are sure that your configuration works fine."




Common Errors The I got stuck with

protocol error: Method Not Allowed The requested method PUT is not allowed for the URL /JavaBridge/JavaBridge.phpjavabridge

"Make sure the port 8080 is free and your servlet server is started on 8080 ONLY"

Undefined index: content_length java bridge Or java.lang.ArrayIndexOutOfBoundsException: 5 protocol error: , Invalid document end at col 1. Check the back end log for details. at php.java.bridge.Parser.PUSH(Parser.java:149) at php.java.bridge.Parser.parse(Parser.java:184) at php.java.bridge.Request.handleRequest(Request.java:373) at php.java.bridge.Request.handleRequests(Request.java:481) at php.java.bridge.JavaBridge.run(JavaBridge.java:213) at php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:58)

The server should be started as

java -jar /var/jdk1.6.0_05/lib/JavaBridge.jar SERVLET_LOCAL:8080
and not
java -jar /var/jdk1.6.0_05/lib/JavaBridge.jar INET_LOCAL:8080