PHP on the Sun Java Application Server 9.0
While reading the Aquarium blog, I found instructions to add PHP to my Sun Java Application Server 9.0.
My experience, on my WindowsXP computer:
* Setup my development environment: Java SE Development Kit (JDK 6), Sun Java System Application Server Platform Edition 9.0 (Glassfish), and NetBeans IDE 5.5.
* Followed Ludovic Champenois's Blog instructions to install the Quercus PHP system into my Sun Java Application Server, using the jar files from the quercus-3_1-snap.war file. If using a 1.5.x JDK version, download jsr223-api.jar, and install into the GLASSFISHINSTALLDIR/lib/addons/ along with quercus.jar, and resin-util.jar from the Quercus war file.
Create GLASSFISHINSTALLDIR/domains/domain1/config/php.ini that contains default_mimetype=text/html
Then create and tested a Hello World sample PHP program.
The main reason for getting PHP to run on my App.Server is to install Moodle, a learning content server.
* I downloaded the Moodle zip file.
* I read the install/setup instructions which let me know I needed MySQL.
* Downloaded and installed MySQL version 4.12 (SetupMySQL412.exe).
* Created a database based on the Moodle instructions.
* Created a new NetBeans project.
* Copied the Moodle application files into my NetBeans project.
* Deployed and ran the Moodle project.
* Upon startup, I ran into string problems which I quickly resolved. When the Moodle install web application did not connect to the database, I setup and tested a simple PHP program to connect to my MySQL database.
*** The following test works, code from PHP.net:
<?php
$link = mysql_connect('localhost', 'root', 'mypasswd');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
Based on this link, I set up the connection on the Sun Java Application Server admin system:
* From the MySQL site, I downloaded the MySQL® Connector/J 5.0. Unzipped it and copied the file mysql-connector-java-5.0.5-bin.jar into my .../domains/domain1/lib directory.
* From the Sun Java Application Server admin system. I added a JDBC Connection Pool (Admin GUI/Application Server/Resources/JDBC/Connection Pools):
Name: MysqlPool
Datasource Classname: com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
Resource Type: javax.sql.DataSource
My DB settings: user: root, Password: mypasswd, Port: 3306, databaseName: moodle, servername: localhost
* Save settings, and do a Ping test from Admin GUI/Application Server/Resources/JDBC/Connection Pools/MysqlPool
* Add JDBC resource, from Admin GUI/Application Server/Resources/JDBC/JDBC Resources: JNDI Name: jdbc/moodleDB, Pool Name: MysqlPool, Enabled: on.
* Add database values into the project's PHP web.xml configuration:
...
<init-param>
<param-name>php-ini-file</param-name>
<param-value>php.ini</param-value>
</init-param>
<init-param>
<param-name>database</param-name>
<param-value>jdbc/moodleDB</param-value>
</init-param>
...
*** I am successful! -> connnect: Connected successfully
Click here to download my NetBeans project which is configured to use the Quercus PHP setup.
Configure NetBeans to execute MySQL Commands
Original instructions from here.* Add MySQL driver by right mouse click on Driver, select Add Driver. My driver location:
C:\Sun\AppServer\domains\domain1\lib\mysql-connector-java-5.0.5-bin.jar
* Connect to the database.
* MySQL database is now available:
Posted at 09:47AM Mar 13, 2007 by Stacy Thurston in Computers | Comments[1]


Posted by ludo on March 13, 2007 at 11:14 AM PDT #