|
Technical Note
Installing Apache, PHP, JDeveloper, and the PHP Extension on Linux
Authors: Chris Jones, Manuel Hossfeld, Matthias Brandl
Publication Date: November 2004
Note: This guide, which offers a high-level yet comprehensive approach to installing PHP and JDeveloper on Linux, was used for the November 2004 Oracle and PHP Installfest at the International PHP Conference in Frankfurt. For detailed install guides relating to specific tasks , see the Open Source Developer Center.
For this demonstration we'll install the components in a user account. For the sake of simplicity, we recommend that you use the "oracle" account. (You won't have to switch users at all this way.)
These steps assume Oracle Database 10g is installed.
Apache 1.3
- Login as Oracle user.
- Copy/download apache_1.3.31.tar.gz
- tar -zxf apache_1.3.31.tar.gz
- cd apache_1.3.31
- Configure:
./configure --enable-module=so --prefix=$HOME/apache --with-port=8888
- Build: make
- Install: make install
- Start Apache: $HOME/apache/bin/apachectl start
- Go to a browser and check that http://localhost:8888/ returns the default "Powered by Apache" page.
- Stop Apache: $HOME/apache/bin/apachectl stop
PHP 4.3
Before you proceed, make sure that the packages "bison" and "flex" are installed, because PHP needs them.
- Copy/download php-4.3.9.tar.gz
- tar -zxf php-4.3.9.tar.gz
- Set environment variable ORACLE_SID
- Set environment variable ORACLE_HOME
- Set environment variable LD_LIBRARY_PATH to $ORACLE_HOME/lib:${LD_LIBRARY_PATH}
- Configure (make sure to enter this as one long line):
./configure --prefix=$HOME/php --with-apxs=$HOME/apache/bin/apxs
--with-config-file-path=$HOME/apache/conf
--with-oci8=$ORACLE_HOME --enable-sigchild
- Build: make
- Install: Make install
- cp php.ini-recommended $HOME/apache/conf/php.ini
- Edit $HOME/apache/conf/httpd.conf and add:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
- Restart Apache
- create $HOME/apache/htdocs/phpinfo.php as:
<?php
phpinfo();
?>
- In a browser load http://localhost:8888/phpinfo.php. Check that the OCI module is listed.
JDeveloper
- Insert your "Oracle Developer CD - Java, Web Services, and PHP" disk.
- Open a browser and load "Start_Here.html" (Many of the links in the sub-pages are to www.oracle.com. Without internet access, these will not work.)
- Click Install Now!.
- Agree to the license.
- Close the popup which asks about OTN Java Newletter.
- Remember the password: 10gJ2EE
- Click on the "Click here" link next to the JDeveloper entry:
- Choose Save to disk.
- Go to a shell.
- Create a directory such as $HOME/jdev9052 and move the ZIP to this directory
- Unzip the ZIP file using the password 10gJ2EE.
- Do: chmod +x <installdir</jdev/bin/jdev
- Run: <installdir>/jdev/bin/jdev
- Enter the full path to your JDK ($ORACLE_HOME/jdk will do).
- Choose Yes to create the working directory.
- Choose No to migrate existing data.
- Navigate to Tools->Preferences->Web Browser and Proxy and set the "Browser Command Line" to your browser, e.g. <firefoxhome>/firefox
Note: You'll have to do steps 10-13 only once. (After that, you could also create a shortcut on your desktop to start JDeveloper.)
PHP Extension
- Follow steps similar to JDeveloper installation to extract the PHP Extension ZIP
- Move the php-addin.jar to <installdir>/jdev/lib/ext
- Restart JDeveloper: <installdir>/jdev/bin/jdev
- Navigate to Tools->Preferences->PHP and set the command line executable to $HOME/php/bin/php
Putting it Altogether
- If you didn't already unlock the database user "scott" at the end of the Oracle 10g installation, run sqlplus system/<your_system_password> and do:
alter user scott account unlock;
exit
- Run JDeveloper.
- In the Applications Navigator select Applications.
- Navigate to File->New. Expand the General node and select Workspaces. In the right hand pane select Workspace and click OK.
- In the "Create Workspace" pane choose a new name: MyWS. Un-check Add a New Empty Project and click OK.
- In The Applications Navigator, right click on your new workspace, MyWS. Choose New.
- Expand the General node and select Projects. In the right hand pane select PHP Project and click OK.
- In the PHP Project Wizard:
- Choose a new name, MyP, and click Next.
- Ignore the URL Mapping page and click Finish.
- In the Applications Navigator, right click on Project. Choose New.
- Expand Web Tier and select PHP. In the right hand pane select PHP File and click OK.
- Change the file name to myoci.php and click OK.
- In the new file, insert the following code, changing "MYSID" to the actual SID (service name) of your database.
<?php
define('ORA_CON_UN', 'scott');
define('ORA_CON_PW', 'tiger');
define('ORA_CON_DB', 'MYSID');
$conn = OCILogon(ORA_CON_UN, ORA_CON_PW , ORA_CON_DB );
if (!$conn) {
exit;
}
echo OCIServerVersion($conn) ."<br>\n";
echo "Connected as ".ORA_CON_UN. "</br>\n";
echo date('Y-m-d H:i:s')."<br><br>\n";
$query = 'select * from emp';
$stid = OCIParse($conn, $query);
OCIExecute($stid, OCI_DEFAULT);
print "<table border='1'>\n";
while ($succ = OCIFetchInto($stid, $row, OCI_RETURN_NULLS)) {
print "<tr>\n";
foreach ($row as $item) {
print '<td>';
print isset($item)?htmlentities($item):' ';
print "</td>\n";
}
print "</tr>\n";
}
print "</table>\n";
OCILogoff($conn);
?>
- When JDeveloper "runs" this file, it will start up your browser with an "http://" URL associated with the file. Apache needs to know the URL-to-file mapping, and JDeveloper needs to know what URL to use. Edit httpd.conf and add the following lines, replacing "/home/cjones" with the home directory of the account you're using (e.g. "/opt/oracle"):
Alias /MyWS/MyP/public_html/ "/home/cjones/jdevhome/mywork/MyWS/MyP/public_html/"
<Directory "/home/cjones/jdevhome/mywork/MyWS/MyP/public_html">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
and restart Apache.
- In the Applications Navigator, right click on MyP and select Project Properties.
- Select PHP Script Execution Settings.
- Add the port number 8888 to the URL, making it http://localhost:8888/MyWS/MyP/public_html/.
- Click Test URL. There should be four lines of output, each testing a variation of the URL. The final row with the full URL should show Success. Click OK.
- In the Applications Navigator, right click on MyP and select Run. Browse the Run Target and use your new file, myoci.php. Click OK. A new browser should open up showing the results of the query.
If you have any questions on this install guide, or about Oracle and PHP in general, please post them in the PHP Discussion Forum.
|