Click to See Complete Forum and Search --> : [RESOLVED] Adding Java Extension to Php/apache/mysql on Windows
Paul R
07-09-2006, 02:09 PM
Stuck again!
I have installed MySQL (4.0.21) with Apache (2.0.52), and
PHP 5.0.2 and successfully integrated them on a Windows XP
system. I am trying to add the Java extension, using the pecl
5.1.2 Win32 download. (Thanks to Pieman60 and Houdini)
After the customary changes in php.ini defining system paths
and setting java.library.path, java.class.path, java.home, and
java.library, I get the following message upon starting up the
Apache server:
"c:\php5\ext\php_java.dll module could not be found."
The mystery is that this file is in fact located in
c:\php5\ext. (As a matter of interest, I sprinkled php_java.dll
in many possible locations and still the system can't seem to
find it. )
Am I misinerpreting the meaning of the message? For example it
may find it but can't run it?
Thanks for any clues to get the mystery solved.
Paul
tsinka
07-09-2006, 02:33 PM
That message could mean that the extension is missing an additional dll. How das the java configuration part in your php.ini look like ?
Thomas
Paul R
07-09-2006, 02:51 PM
Hello Thomas,
Here is a copy of the java confi part of php.ini:
;extension=php_yaz.dll
;extension=php_zip.dll
extension=php_java.dll
[java]
;This must point to the location of php_java.dll.
java.library.path = "c:\php5\ext\"
;This points to the directory where your java
;classes will be stored. You can designate multiple
;paths, each path separated by a semicolon.
;It also must include the location of php_java.jar
java.class.path = "c:\php5\jdk1.5.0_06\php_java.jar;
c:\Program Files\java\jdk1.5.0_06"
;This points to the bin directory of the jdk.
java.home = "c:\Program Files\java\jdk1.5.0_06\bin"
;This must point to the Java Virtual Machine (jvm.dll) file
java.library = "c:\Program Files\java\jdk1.5.0_06\jre\lib\bin\server\jvm.dll"
tsinka
07-09-2006, 03:04 PM
In the first post you wrote that you tried to integrate the java extension of PHP 5.1.2 with PHP 5.0.2. That may be a problem. I'd suggest to download and install the extension that matches your version here (http://www.php.net/get/pecl-5.0.2-Win32.zip/from/a/mirror) .
Thomas
Paul R
07-09-2006, 03:44 PM
Thank you Thomas. I will try your suggestion.
Paul
Paul R
07-09-2006, 04:28 PM
Thomas
Good news. I was able to start Apache OK ,so at this point it looks like java has a chance of running OK. It will probably take me a day to check this out. I will post to let you know of the results.
Thank you for the great suggestion!
Paul
tsinka
07-09-2006, 04:45 PM
You can check that the extension has been loaded with a little phpinfo script. The output should contain a java extension section. A first step to see if the extension has been loaded with correct settings.
Thomas
Paul R
07-09-2006, 06:13 PM
Thomas.
I successfully ran the phpinfo script, and indeed do have a java section!!
It looks like you were exactly correct on the version problem.
Thanks again. I will do a complete test tomorrow and let you know the results.
Paul
Paul R
07-10-2006, 12:40 PM
Thomas,
After yesterday's success, I thought I was into clear sailing. But, I am unable to execute the java part of a simple program.
java.class.path ="c:\javaclasses ; c:\php5\php_jar" with my helloapp.java and helloapp.class located in the c:\javaclasses.
My php file : helloapp.php is located in c:\program Files\apache\apache2\htdocs
The helloapp class program contains the main and inside of that system.out.print statement of "helloworld". My php file is a one liner: exec("java Helloapp"}; (This statement was enclosed in <? php and ?> .
php runs fine, but it is the embedded java that doesn't work. Am I on the right track?
tsinka
07-10-2006, 12:54 PM
Ok,
you don't need the exec line. It's more like java being accessible directly through PHP.
The manual (http://de.php.net/java) contains some simple examples.
Thomas
Paul R
07-10-2006, 02:09 PM
Sorry, I don't understand how to run example 1. I thought one has to first compile a java source program creating a .class file from a .java source. Then one would run the php program which contains a reference to the .class file. (By the way, I tried the Example 1 called in the Apache htdocs file. System locked up!)
Paul
tsinka
07-10-2006, 04:59 PM
How does the java section look like in the phpinfo() output ?
Paul R
07-10-2006, 06:08 PM
Here is the info in the java section of phpinfo:
java
Directive Local Value Master Value
java.class.path
(local value) c:\php5\php_java.jar;c:\javaclasses
(master value) c:\php5\php_java.jar;c:\javaclasses
java.home
(local value)c:\Program Files\java\jdk1.5.0_06\bin
(master value)c:\Program Files\java\jdk1.5.0_06\bin
java.library
(local value)c:\Program
Files\java\jdk1.5.0_06\jre\lib\bin\server\jvm.dll
(master value)c:\Program
Files\java\jdk1.5.0_06\jre\lib\bin\server\jvm.dll
java.library.path
(local value) c:\php5\ext\
(master value)c:\php5\ext\
Hope you could read this OK
Paul
tsinka
07-10-2006, 06:42 PM
Ok,
I think the java_home path is wrong.
Copy the php_java.jar to the ext folder and then try the following settings:
java.class.path="C:\php5\ext\php_java.jar;C:\javaclasses;C:\Program Files\java\jdk1.5.0_06\jre\lib;C:\Program Files\java\jdk1.5.0_06"
java.home="C:\Program Files\java\jdk1.5.0_06"
java.library="C:\Program Files\java\jdk1.5.0_06\jre\bin\server\jvm.dll"
java.library.path="C:\php5\ext;C:\Program Files\jdk1.5.0_06\jre\lib"
I'm not sure if those settings are completely correct. Check the paths. I checked my jdk 1.5.0_06 installation and the jvm.dll is in ...\jre\bin\server and not in ..\jre\lib\bin\server.
An alternative is the PHP/Java bridge (http://php-java-bridge.sourceforge.net/). I compiled and successfully used it on a linux box but there's a binary package available that contains the windows files, too. Those file are packaged in the .war file that comes with the zip package.
Thomas
Paul R
07-10-2006, 10:17 PM
Thomas,
I implemented all of your file changes, and still get no response from java.
I looked at the Apache error log for the last time I tried to connect. It read something like:
"java.lang.noClassDefFoundError: javaprog."
javaprog is the .class file that contains the compiled java code. Perhaps this is a clue.
Thanks again for your patience and help.
Paul
tsinka
07-11-2006, 03:27 AM
That means that java couldn't find your class.
What about this example (taken from the manual) ?
<?php
// get instance of Java class java.lang.System in PHP
$system = new Java('java.lang.System');
// demonstrate property access
echo 'Java version=' . $system->getProperty('java.version') . '<br />';
echo 'Java vendor=' . $system->getProperty('java.vendor') . '<br />';
echo 'OS=' . $system->getProperty('os.name') . ' ' .
$system->getProperty('os.version') . ' on ' .
$system->getProperty('os.arch') . ' <br />';
// java.util.Date example
$formatter = new Java('java.text.SimpleDateFormat',
"EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");
echo $formatter->format(new Java('java.util.Date'));
?>
Execute this script and check if it prints anything. Check the error log if it contains any error.
Please post the source file of your java example as an attachment.
Paul R
07-11-2006, 10:32 AM
Thomas,
I placed your test php file(Thomas.php) in c:\Program Files\Apache Group\Apache2\htdocs. (I think that this is where it should be placed. Correct??)
When I went to the browser and went to http://localhost/thomas.php I get a pop up message box saying: "Apache HTTP server has encountered a problem." I looked at the error report and it was as follows: "szAppName:Apache.exe szAppVer 2.0.52.0"
The Apache error log didn't show anything unusual. (something about aquiring the start mutex).
I will send another message with my test program which you asked for.
To be sure I understand, I put all .php files that I wish to post in the htdocs file. I put all .class files associated with these .php files in c:\javaclasses which is on the java.class.path.
Is this correct?
(These .class files were created by separately compiling .java files.)
In the case of Thomas.php there is no associated .java file so there is no compiling to be done. Correct?
Thanks again for sticking with this.
Paul
Paul R
07-11-2006, 10:50 AM
This is a second message, please read the first one that I wrote a few minutes ago.
Here is the test code that I have been using.
<?php
echo "Hello World!" ;
$output = array();
$return_var = 0;
exec("java javaprog", $output, $return_var);
$output_str = join($output, "\n");
echo "<pre>The output was:\n$output_str\n\n";
echo "The return value was $return_var</pre>";
?>
// Here is javaprog.java
public class javaprog
{
public static void main(String[] args)
{
System.out.println("Printed by Java program");
System.exit(8) ;
}
}
tsinka
07-11-2006, 10:55 AM
The error message means that apache crashed with the test script I posted. That's a bigger problem meaning that for some reason the java extension is instable.
Your script executes java externally with the exec function. You don't need the java extension for that. The java extension enables PHP to access java classes in a PHP like style.
Please give me more info about your setup (apache version, php version, MySQL version, ....).
I'll try to reproduce the problem.
Thomas
Paul R
07-11-2006, 04:25 PM
I hope this helps:
System:
MS Windows XP Media Center Edition Version 2002 Service Pack 2
IE 6.0
AMD Athlon Prcoessor 3700+
Java version jdk1.5.0_06
Apache Version 2.0.52
PHP Version 5.0.2
MySQL Server 5.0
PECL (java pecl for PHP) 5.0.2
I am still quite confused.
Question 1 My test program required that I off line compile the .java file. Then The system should be able to locate the corresponding .class file. Is this correct? You are saying that doing things this way does not require adding the java extension.? If this is true is it sufficient to store the .class file in java.class.path ? If the java extension were working, php would automatically compile the .java file??
Question 2 Your test program calls up some java classes. These are part of the java.lang,system package which are usually loaded automatically in java. Therefore the java extension seems to be able to find these classes. Correct? I there were any external new classes these would have had to be converted to .class files ?
Comment: Due to my unfamiliarity, I have a feeling that part of the problem here is my misunderstanding of what is going on. (So called "****pit problems")
Paul
Paul
tsinka
07-11-2006, 04:53 PM
Hi,
I was able to reproduce your problem. Apache crashed whenever I tried to do some java stuff.
But I was able to solve the problem on my machine by using the PHP/Java bridge (http://php-java-bridge.sourceforge.net/).
What you need to do:
1) upgrade to the latest php 5.0 version (php 5.0.4). You can download it by clicking on the "our releases page" link on the left side of the download page.
Download the php 5.0.4 windows binary and the corresponding pecl package (the "collection of pecl modules" link in the php 5.0.4 download section). You need php 5.0.4 because the bridge is incompatible with 5.0.2
2) download the php/java bridge and extract the archive. There will be a .war file besides some other files. Rename the file to .zip and open it with winzip. Extract JavaBridge.jar and copy it to the <PHP>\ext directory. Extract php-5.0-java-x86-windows.dll, rename it to php_java.dll and also copy the file to <PHP>\ext.
3) Edit php.ini and replace the java settings lines with:
java.java = "C:\Java\jdk1.5.0_06\bin\javaw.exe"
java.java_home = "C:\Java\jdk1.5.0_06"
java.log_level = 3
java.libpath = "C:\WAMPP\php5\ext"
java.class.path = "C:\WAMPP\php5\ext\JavaBridge.jar"
(modifiy the paths so that they match your java/php installation)
Then execute the test script I posted above. It worked multiple times without any crashes on my system.
One hint: Normally you need to add your own custom jar files to the class path. Instead of modifying php.ini and adding the jar files to the classpath you can do the following:
$javaLibs ="file:c:/php5/ext/JavaBridge.jar; file:c:/path/to/my/file.jar;
file:c:/path/to/my/second/file.jar";
java_require($javaLibs);
If you want to use class files instead of jar files then put the class files in one of the classpath directories. But you have to put them in a directory structure that matches the packages of the classes.
Example:
In your case you have C:\javaclasses in your classpath. If one of your classes (named "myClass") is in package com.paulr.projects.phpproject1 then make sure to copy the class file to C:\javaclasses\com\paulr\projects\phpproject1 and then do this:
$myClass = new Java("com.paulr.projects.phpproject1.myClass");
But the first step is to test the script I posted. I hope I didn't make things too complicated.
Thomas
Paul R
07-11-2006, 05:45 PM
Wow! That is good that you reproduced the problem. but it looks like a major change which I am about to try out. First, do you recommend uninstalling the old php and its pecl, as well as Apache and MySQL ??
Paul
tsinka
07-11-2006, 05:57 PM
This is what I did:
I just stopped apache and renamed the complete php directory. Then I extracted the new php and pecl packages so that the php directory was the same like before (I think you may need to copy the pear stuff if you installed additional pear packages). You don't need to reinstall apache, mysql or any other software (just php). Copy the additional dlls that come with the new php version over the old dlls (php5ts.dll, libmysql.dll, libmash.dll ... just any dlls that you copied to system32. In my case I copied that additional dlls into the apache bin directory so that I didn't have to mess around with the system32 directory).
Just completely replace the old php installation (but not the php.ini) with the new one and follow the additional steps in my last post.
Thomas
Paul R
07-11-2006, 10:06 PM
I will go forward with this (with great courage) tomorrow, and let you know if I reach friendly shores.
Paul
Paul R
07-12-2006, 11:18 AM
Thomas
I got through your first step of updating php OK.
Next(step 2) you say to download php/java bridge. Where is this download located. What is the title of it? I think I need a little more detail here.
Thanks,
Paul
tsinka
07-12-2006, 11:45 AM
The link was in my last big post (but a little hard to find):
http://php-java-bridge.sourceforge.net/
There's a download link near the bottom of the page ("Installation instructions"). It's a link to sourceforge.net where you can download php-java-bridge_3.1.4_j2ee.zip. That zip file contains the .war file I was writing about.
Thomas
tsinka
07-12-2006, 02:15 PM
I tested the whole stuff with your class but It didn't display anything directly in the browser. System.out.println will print out to the error_log.
Test this one:
public class javaprog
{
private int i = 0;
public int incAndGet()
{
i++;
return i;
}
public void printMe()
{
System.out.println("Me");
}
}
and
<?PHP
java_require("C:\javaclasses");
$my = new Java('javaprog');
for ($i=0;$i<10;$i++) {
echo $my->incAndGet()."<br>\n";
}
$my->printMe();
?>
use java_require to add your custom directories to the classpath. You need to restart apache each time you modify and recompile your java classes because some sort of caching is implemented in that bridge.
The incAndGet() function increments and returns an int that you can print
The call to printMe() will print "Me" to the error_log.
I'll check if there's a way to redirect output to the browser ...
Thomas
Paul R
07-12-2006, 02:56 PM
I finally got through the conversion to java bridge. Unfortunately I have now no indication of java in the phpinfo output. (Should I see this?) I suspect that I misintrpreted something. I have kept the old php.ini and semicoloned the old directive lines:
java.library.path, (old)java.class.path, java.home, and java.library.
They are replaced with java.java, java.java_home, java.log_level,java.libpath,and java.class.path. If you care to see what the current status of php.ini here it is:
extension=php_java.dll
[java]
;This must point to the location of php_java.dll.
;java.library.path = "c:\php5\ext;C:\Program Files\java\jdk1.5.0_06\jre\lib"
;This points to the directory where your java
;classes will be stored. You can designate multiple
;paths, each path separated by a semicolon.
;It also must include the location of php_java.jar
;java.class.path = "c:\php5\ext\php_java.jar;
;c:\javaclasses;C:\Program Files\java\jdk1.5.0_06\jre\lib;C:\Program Files\java\jdk1.5.0_06"
;This points to the bin directory of the jdk.
;java.home = "c:\Program Files\java\jdk1.5.0_06"
;This must point to the Java Virtual Machine (jvm.dll) file
;java.library = "c:\Program Files\java\jdk1.5.0_06\jre\lib\bin\server\jvm.dll"
java.java = "c:\Program Files\java\jdk1.5.0_06\bin"
java.java_home = "c:\Program Files\java\jdk1.5.0_06"
java.log_level = 3
java.libpath = "c\php5\ext"
java.class.path = "c:\php5|ext\JavaBridge.jar;c:javaclasses;c:\php5\ext\php_java.jar"
I am placing your php program to be run under htdocs in Apache. Is this correct?
tsinka
07-12-2006, 03:12 PM
Did you replace php_java.dll with the dll in the .war file ?
Replace the java configuration directives in php.ini with:
java.java = "c:\Program Files\java\jdk1.5.0_06\bin\javaw.exe"
java.java_home = "c:\Program Files\java\jdk1.5.0_06"
java.log_level = 3
java.libpath = "c\php5\ext"
java.class.path = "c:\php5\ext\JavaBridge.jar"
Then restart apache and check if the output of the phpinfo script contains a Java section.
Thomas
Paul R
07-12-2006, 04:12 PM
I did replace php_java.dll with the new one.
Also corrected my php.ini file to look like yours.
Still no phpinfo containing a java section.
should php.ini still have the line "extension =php_java.dll" before the [java] section?
tsinka
07-12-2006, 04:15 PM
Interesting,
you should at least get a warning if the extension couldn't be loaded. Please post php.ini as attachment and check the apache error_log for any messages about the java extension.
Thomas
tsinka
07-12-2006, 04:49 PM
Additional notes:
1. the php.ini must contain php_java.dll
2. modifiy the extension=php_java.dll line so that it looks like e.g. extension=php_java2.dll. Then restart apache. You should get a message box with an error message about php_java2.dll. If you don't get such a message then check the "Configuration File (php.ini) Path" line in the phpinfo output and double check that it points to the correct php.ini file (the one you modified).
3. check the apache startup line in the error_log. It should contain a reference to PHP 5.0.4
Thomas
Paul R
07-12-2006, 04:55 PM
I found the following php warning in the Apache error log associated with trying to get phpinfo to recognize java.
[Wed Jul 12 15:05:21 2006] [notice] Parent: Child process exited successfully.
[Wed Jul 12 15:05:27 2006] [notice] Parent: Created child process 30352
PHP Warning: PHP Startup: Unable to load dynamic library 'c:\\php5\\ext\\php_java.dll' - The specified procedure could not be found.\r\n in Unknown on line 0
[Wed Jul 12 15:05:28 2006] [notice] Child 30352: Child process is running
[Wed Jul 12 15:05:28 2006] [notice] Child 30352: Acquired the start mutex.
[Wed Jul 12 15:05:28 2006] [notice] Child 30352: Starting 250 worker threads.
[
Also see attached php.ini (I had to change the name to a .doc to make it an attachement.)
tsinka
07-12-2006, 05:11 PM
I think I forgot the most important part:
After upgrading your php installation you need to copy the php dlls (php5ts.dll,libeay.dll....) over the existing ones (apache\bin or system32, wherever you copied them). You need to shutdown apache first.
Thomas
tsinka
07-12-2006, 05:13 PM
The exact same error message was the reason for me to upgrade to the most recent php 5.0.4 version. The older versions don't have some symbols the extension needs.
Thomas
Paul R
07-12-2006, 06:05 PM
I copies all the .ini files from the new PHP5 to c:\windows\system32. these included php5apache2.dll, php5ts.dll php_mysql.dll and ligmysql.dll. (I could not locate a new version of mysqli.dll. )
Next a tried to run phpinfo again, but still no recognition of java. I didn't see any errors in the log on this.
However, when I tried to run your program (Thomas.php) I got a warning in the error log: "Unable to load dynamic library c:\php5\ext\php_java.dll.
I also got a message in the browser saying ( something like) "procedure in line 3 could not be found"
tsinka
07-12-2006, 06:43 PM
Ok,
some setting or dll version is wrong. Please save the output of phpinfo to a file and post it.
I think the last option is to start with a clean install of apache 2.0.58 and php 5.0.4.
This would include removing any php related files from the system32 and windows directory. It's a little bit easier to copy the dlls and ini files to the apache\bin directory instead. This is the best way to make sure that apache doesn't use the wrong dlls.
Thomas
Paul R
07-13-2006, 09:15 AM
Thomas,
I will follow your suggestion and wipe out the old Apache and php. and then reinstall. Do I understand that I can put all of my .dll that used to reside in the system32 directory into the /bin directory of Apache?
Paul
Paul R
07-13-2006, 09:26 AM
I have been using the latest version of php: php5.1.4, and you have been using 5.0.4
Should I go back to 5.0.4??
Paul
tsinka
07-13-2006, 10:30 AM
That's it. I tried it with 5.0.2, 5.0.4 and 5.1.x. The bridge doesn't work with PHP 5.1.x and some older 5.0.x versions (like 5.0.2). You need to go back to 5.0.4 to use the bridge.
Thomas
tsinka
07-13-2006, 10:32 AM
Wait ... I think I'm wrong. You just need to use another dll from the .war file. There's a dll specifically for php 5.1. I was wrong ... first try to use the 5.1 dll in the .war file.
Sorry, I got a little bit confused.
Thomas
tsinka
07-13-2006, 10:41 AM
I checked the package.
It's the file: java-x86-windows.dll
Overwrite the existing php_java.dll in your php 5.1 installation with that file. Then restart apache.
Thomas
Paul R
07-13-2006, 11:03 AM
I just finished removing all php* files from the system as well as PHP and Apache. I think the system is now clean. Even though there is a major new revision of Apache (2.2.2) I am sticking with your version 2.0.58
I am about to download the PHP version 5.1.4 which I gather from the above is OK. Then I will start on the bridge stuff.
Paul
Paul R
07-14-2006, 03:05 PM
Thomas, hope you are still there. I have been working pretty steadily on this since we last communicated. Here is a current statement of the situation:
I have now reloaded php and Apache and the java/PHP bridge.
Results: I can now see a java section in phpinfo. (which we could not get before!) However when I try to run your program thomas.php, I get the following error in the browser (none in the apache log):
Fatal error: java() [<a href='function.java'>function.java</a>]: Unable to load Java Library jvm.dll, error: The specified module could not be found. in c:\Program Files\Apache Group\Apache2\htdocs\thomas.php on line 3
Note: I had to put an " extension = php_java.dll " statement in the php.ini file to get the phpinfo to work.
Also, I noticed that in the java section of phpinfo, the following assignments were made:
java.home no value
java.library jvm.dll
java.library.path no value
I kept careful track of the steps involved in getting the bridge up and I have notes on it if the problem centers on that. I had some questions about interpretation about some of your bridge instructions.
Probably this is enough until you get a chance to look at this.
Paul
tsinka
07-14-2006, 03:15 PM
I'm still here :)
The phpinfo output that you posted looks like the pecl php_java.dll output. You need to copy the JavaBridge.jar and the java-x86-windows.dll (rename it to php_java.dll) from the war file to the ext directory.
Then replace the java settings in php.ini with:
java.java = "c:\Program Files\java\jdk1.5.0_06\bin\javaw.exe"
java.java_home = "c:\Program Files\java\jdk1.5.0_06"
java.log_level = 3
java.libpath = "c\php5\ext"
java.class.path = "c:\php5\ext\JavaBridge.jar"
and restart apache.
You may need to adjust the paths to match your installation paths.
As a reference I send the phpinfo java section of my php 5.1 installation:
java support Enabled
java bridge 3.1.4
java.libpath C:\WAMPP\php5\ext
java.java_home C:\Java\jdk1.5.0_06
java.java C:\Java\jdk1.5.0_06\bin\javaw.exe
java.log_file <stderr>
java.log_level 3
java.ext_java_compatibility Off
java.persistent_connections On
java.security_policy Off
java command C:\Java\jdk1.5.0_06\bin\javaw.exe -Djava.library.path=C:\WAMPP\php5\ext -Djava.class.path=C:\WAMPP\php5\ext/JavaBridge.jar -Djava.awt.headless=true -Dphp.java.bridge.base=C:\WAMPP\php5\ext php.java.bridge.JavaBridge INET_LOCAL:0 3
java status running
java server 9268
Thomas
Paul R
07-14-2006, 04:56 PM
I did what you said and now I have lost the phpinfo output altogether.
Please review what I did with regard to the javabridge part of the procedure:
1 Created ext folder under c:\php5.
Now have c:\php5\ext
2 downloaded php-java-bridge_3.1.4_j2ee.zip
3 Extracted zip file to c:\php5\ext
Now have single folder in ext :c:\php5\ext\php-java-bridge3.1.4_j2ee
4 Can see JavaBridge.war in this folder.
Changed the name of this file to JavaBridge.war
Unzipped this to : c:\php5\ext
5 You said to extract php-5.0-java-x86-windows.dll
I'm not sure what you mean here by "extract"? At any rate I searched and found this file in c:\php5\ext\WEB-INF\cgi
(Is this correct?) Anyway, i renamed it to php_java.dll
6 then I copied the new php_java.dll to c:\php5\ext
That was it, before your last transmission.
This time you called out java-x86-windows.dll to turn into php_java.dll
instead of the previous php-5.0-java-x86-windows.dll
Which should I use?
Paul
tsinka
07-14-2006, 05:32 PM
This is what you need to do:
Let's say you have finished a clean install of apache and php. Let's say you installed php to C:\php5. The ext directory is part of the php package so the directory C:\php5\ext should already exist after installing php.
The additional steps:
1. download php-java-bridge_3.1.4_j2ee.zip
2. extract the zip file to any directory you want, let's say to C:\javabridge (but not to C:\php5)
3. rename C:\javabridge\php-java-bridge-3.1.4_j2ee\JavaBridge.war to C:\javabridge\php-java-bridge-3.1.4_j2ee\JavaBridge.zip
4. Extract C:\javabridge\php-java-bridge-3.1.4_j2ee\JavaBridge.zip to C:\javabridge
5. copy C:\javabridge\WEB-INF\lib\JavaBridge.jar to C:\php5\ext
6. Depending on the PHP version you installed copy the appropriate dll to C:\PHP5\ext and rename it to php_java.dll
PHP 5.0.x: php-5.0-java-x86-windows.dll
PHP 5.1.x: java-x86-windows.dll
Add the java configuration settings I posted to php.ini (with correct paths)
Restart apache.
You just need to copy JavaBridge.jar and the dll that matches your php version as php_java.dll to the ext directory. You don't need any other files contained in the java bridge package. Then modify php.ini.
If it still doesn't work then post your php.ini as attachment. Additionally I need the PHP and Java installation paths and the PHP version you installed. I'll then post you the modified php.ini and a zip file containing the two files you need.
That "module not found" error message in the error_log means that the bridge dll doesn't match the PHP version.
Thomas
Paul R
07-14-2006, 06:28 PM
Thomas,
I am very concerned that I apparently did not get a clean installment of php since the ext subdirectory did not appear. I guess I will start again and see if I can find out why! There is probably little to be gained by going forward without this being fixed. So, I will start again!
sigh,
Paul
tsinka
07-14-2006, 06:54 PM
I sent you a PM.
Paul R
07-15-2006, 09:22 AM
Thomas,
I think you discovered what has been wrong. There is no appropriate LoadModule directive in httpd.conf. !!!
What should this directive be set to?
I am in the process of installing your woreking installation.
Paul
tsinka
07-15-2006, 09:28 AM
Just the two lines that activate the PHP module at all
The simplest way based on a clean apache install and assuming that you have php in C:\php5:
Modify httpd.conf and add
at the end of the LoadModule block:
LoadModule php5_module C:\php5\php5apach2.dll
and somewhere below that block
AddType application/x-httpd-php .php
Thomas
Paul R
07-15-2006, 10:52 AM
Thomas,
Success, I can run your program ! I can't thank you enough.
A couple of details:
Setting java.class.path to find phpjava.jar is not possible since I do not have php_java.jar anywhere in my system. Is this serious??
In php.ini I set a doc_root to <apache dir>htdocs Is this OK?
So you suppose all our difficulties were a result of not having that LoadModule directive in httpd.conf ???
tsinka
07-15-2006, 11:16 AM
These are the php.ini settings:
java.java = "c:\Program Files\java\jdk1.5.0_06\bin\javaw.exe"
java.java_home = "c:\Program Files\java\jdk1.5.0_06"
java.log_level = 3
java.libpath = "c\php5\ext"
java.class.path = "c:\php5\ext\JavaBridge.jar"
you need to set java.class.path to JavaBridge.jar. php_java.jar is the jar file of the pecl extension. Be careful not to mix up the pecl version of java support and the php/Java bridge.
I think that there were two problems:
1. some kind of mixup between the pecl java support and the PHP/Java bridge
2. version incompatibilities, like using the php 5.0 version of the bridge with php 5.1 and vice versa
One last important note:
In order to use your custom classes and jar files you need to include them with java_include before you can use them in your php scripts, like e.g.
java_include("C:\javaclasses;C:\javaclasses\mycustomjar.jar");
If you have any jar files in e.g. C:\javaclasses then you need to add them to the java_include string separately because adding only C:\javaclasses will include only .class files in C:\javaclasses. You don't need to include each .class file in the java_include string but you need to make sure that the class files reside in a directory structure that matches the package(s) used in the class files.
Example: You have a class named test in package com.mydomain.myproject.mysubpackage
Then create a directory structure C:\javaclasses\com\mydomain\myproject\mysubpackage and put test.class in the mysubpackage directory.
Thomas
tsinka
07-15-2006, 11:19 AM
I'd suggest to mark this thread resolved if you don't have any further questions regarding this installation issue and opening a new thread if you have any questions about using php with java at all.
Thomas
Paul R
07-15-2006, 12:28 PM
Thanks Thomas.
Your last note concerning the issue of how to combine classes with php was very helpful.
Best Regards and thank you,
Paul
PHP Builder
Copyright WebMediaBrands Inc. All Rights Reserved.