Special thanks to Alex who helped me get this going. He helped me by email a fair bit when PHPbuilder was down.
This document outlines how I installed apache with php including java
Pre-install and download
This was the initial setup for my machine. If you already have this stuff installed good luck a lot of my early problems were because stuff was in weird dirs because of RPMs etc. I gave up on it and just did a vanilla install of the below mentioned packages. But, to be honest I do not really know this stuff all that well either so it was difficult to keep it all staight in my head that is why I did the basic install.
- Install RH7 on a machine using custom install.
- Install everything but SQL/APACHE
- download APACHEx.TAR into /usr/local/src from apache.org
- download PHPx.TAR into /usr/local/src from php.net
- download J2SDKx.TAR into /usr/local from blackdown.org
JDK install
I finally got this to work with Blackdown's JDK as SUN was at rev1. which wants you to use hotspot jvm which I could not get to work as of yet.
- untar j2sdkx.tar.bz2 (tar -xvIf)
- edit your /etc/profile and put that your statement match the following
PATH="$PATH:/usr/X11R6/bin:/usr/local/jdk1.2.2/bin:/usr/local/jdk1.2.2/jre/bin"
CLASSPATH="/usr/local/jdk1.2.2/jre/lib/rt.jar:/usr/local/apache/htdocs"
LD_LIBRARY_PATH="/usr/local/jdk1.2.2/jre/lib/i386:/usr/local/jdk1.2.2/jre/lib/i386/classic:/usr/local/jdk1.2.2/jre/lib/i386/native_threads"
- make sure that you put CLASSPATH and LD_LIBRARY_PATH at the end of the EXPORT line as well
the explanation of the before mentioned is as follows
PATH-- This should contain directories that contain runnables
CLASSPATH-- This one should contain jars or directories containing .class or .properties files
LD_LIBRARY_PATH-- This is equivalent to specifying java.library.path in php.ini
The first of two APACHE installs
1. go to /usr/local/src
2. unzip and untar the apache
3. chdir to apachex
4. mkdir /usr/local/apache
5. from /usr/local/src/apache_x run ./configure (you do not have to specify any options if you want just a vanilla install. Everything will be installed in /usr/local/apache)
6 type make
7 type make install
The PHP install
1. go to /usr/local/src
2. unzip and untar phpx.tar.gz
3. cd phpx
4. ./configure --with-apache=/usr/local/src/apache_x --with-java
5. make
6. make configure
at this point PHP should be step to allow apache to compile in php/java support. there should be a bunch of php stuff under /usr/local/lib. You do not need to worry about this yet but you should be preparing yourself to worry a lot.
The Second Apache install
-the first was just a preparation so that php can the the apache configuration (I think)
1. cd /usr/local/src/apache_x
2. ./configure --activate-module=src/modules/php4/libphp4.a (libphp4.a won't be there but it will copy it over during the install) If you get an error message at the start of the ./configure where it says it is activating modules and it says it can't find file or dir libphp4.a your screwed. blow away all your dirs and start again. It was the only way I could fix it but again I do not know what I am doing (truly dangerous)
3. make
4. make install
At this point you have 2 things to do. Enable module in apache httpd.conf and setup your php.ini. If you do not have a tense feeling in the pit of your stomach yet you should really start thinking about it now.
HTTPD.CONF Edit
1. Edit the httpd.conf file. If you did a vanilla install it should be /usr/local/apache/conf/httpd.conf
2. find the lines that look like
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
and remove the pounds signs (un remarks them) or marks them I guess?
3. save the file
PHP.INI Edit
1. go to the directory /usr/local/lib.
You should see a bunch of PHP files there. PHP.INI, PHP_JAVA.JAR and a PHP directory. In the 2 dozen or so times that I rebuilt this thing sometimes the php.ini showed up automatically and sometimes it did not. I am not to sure why or if this is a figment (or fragment) of my imagination. However, if php.ini is not there but php_java.jar and the php directory are you are still ok. If none of it is there and you did not specify a prefix statement when configuring PHP you are screwed. Delete all source dirs and start again. This happened to me about 1 out of 6 times when rebuilding the web server. Again I do not know why of if this was just because I was so frustrated that frickin torvalds guy decided to play a few sick tricks on me but IT DID HAPPEN I SWEAR IT.
- If the php.ini file exists goto step 3. If not do the following
cp <phpdist>/php.ini-optimize /usr/local/lib/php.ini
- Edit the php.ini file and find the section [java]
- Add the following
java.class.path=/usr/local/lib/php_java.jar:/usr/local/apache/htdocs
java.library.path=/usr/local/lib/php/extensions/no-debug-non-zts-20001214:/usr/local/jdk1.2.2/jre/lib/i386:/usr/local/jdk1.2.2/lib/i386/classic:/usr/local/jdk1.2.2/jre/lib/i386/native_threads
java.home=/usr/local/jdk1.2.2
extension_dir=/usr/local/lib/php/extensions/no-debug-non-zts-20001214
extension=libphp_java.so
Explanation
java.class.path- should point to the dir that has your php_java.jar and the directoryies that you have your classes in for your web page. In my case it was /usr/local/apache/htdocs. I was told by that you did not need to specify anything but your php_java.jar dir if it was already in your classpath but it did not work until I did.
java.library.path- only list directories that contain shared libraries (whatever.so usually). If you di the make/make install it will be in a big long ass directory tree like above. Also specify the jdk dirs as above.
java.home -base directory of JDK
extension/extension_dir -location of libphp_java.so
A quick note about SUN's jdk. I tried like a bastard to get this to work with SUN's jdk but could not. I was told that "That used to be the case since the Sun JDK didn't support native_threads a while back and until the fix to the config.m4 file I mentioned PHP/Java didn't support the new directory structure of the Hotspot JDKs."
I was told the following
You're using a Hotspot JDK. Change all references to .../i386/classic to .../i386/Hotspot. You might also need to pick up a newer version of the <php4>ext/java/config.m4 to pick up a fix that enables support for Hotspot JDK's. You can get it from the php viewcvs at http://cvs.php.net/viewcvs.cgi/~checkout~/php4/ext/java/config.m4?rev=1.22&content-type=text/plain. After replacing the above copy, you'll need to run ./buildconf and then ./configure/make/make install again
This did not work for me so I had to go to Blackdown. I will try again though
There it is you should be able to fire up your apache web server and away you go (/usr/local/apache/bin/apachectl start). If you are like me and know nothing about programming but were asked to get this to go on your web server. These will test your server for you
First make sure your web server is running by typing localhost in the url. If you don't see the Apache web page (the first line will be text saying If you can see this)you screwed up. Start again. If you see it at least you know you built the apache web server properly
Second make a file called first.php with the following lines in it.
<?php
phpinfo();
?>
In the url type localhost/first.php. If you get a more grahical page with your version of php and so on you know you at least have php running. This is a very good page for troubleshooting. If it asks you save file as type or whatever else you have two options 1. either php is not working then start all over. 2. you forgot to activate the modules in the httpd.conf. If this happened to you then I bored you with all my typing and you are pissed at me for being so long winded
To test the php/java portion of it. create a file called jtest.php and put the following lines in it.
<head>
<title>Untitled</title>
</head>
<body>
<?
$obj = new Java("jtest");
echo($obj->getString());
?>
</body>
The create a file called jtest.java put the following lines in it then compile it (to comple it type javac jtest.java)
public class jtest
{
public static String getString()
{
return "It Worked";
}
}
Then you should have a jtest.class there.
In navigator type in jtest.php hold your breath and hit enter. If you see the line It Worked you did it. If not and you saw the PHP info then you have a path problem.Start scewing around. Have fun.
thunderboy