Apache2.2 + PHP5.2 + OCI8/PDO_OCI from sketch on Debian sid HOWTO

This simple HOWTO will guide you about how to setup Apache2.2 + PHP5.2 + OCI8/PDO_OCI from sketch. Compile all package from tarball can give you the maximum flexibility of functionality, e.g. you can enable both mysql/mysqli/pgsql/oci8/pdo_mysql/pdo_pgsql/pdo_oci within single installation.

Before start, I will assume you have Debian sid and Oracle 11gR1 installed correctly, which will not detail within this document. If you really need some help for that, please refer to my other article for more indeed guideline.

Download manual install packages

Get all of the below packages, and place them under /usr/local/src:

Install required packages

Debian apt-get can give us a great hand when prepare system for building custom packages from sketch. Just simply run this command:

apt-get update
apt-get build-dep apache2 php5

Install Apache2.2

Configure Apache2.2 source, compile, and install it:

cd /usr/local/src
tar zxvf httpd-2.2.9.tar.gz
cd httpd-2.2.9
./configure --enable-suexec --enable-rewrite --enable-so
make
make install

You should retouch the Apache configuration. Edit /usr/local/apache2/conf/httpd.conf and take the similar change as below:

User www-data
Group www-data
ServerAdmin root@localhost
DocumentRoot "/var/www"
<Directory "/var/www">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Also need to ensure Apache have correct privilege to access its document root:

chown -Rf www-data:www-data /var/www

Symbolic link all Apache execute binaries to /usr/local/bin:

ln -s /usr/local/apache2/bin/* /usr/local/bin/

Remove the /etc/init.d/apache2 and replace it as a symbolic link to /usr/local/bin/apachectl:

rm -rf /etc/init.d/apache2
ln -s /usr/local/bin/apachectl /etc/init.d/apache2

Ensure your Apache will start automatically during system boot:

update-rc.d -f apache2 remove
update-rc.d -f apache2 defaults 91 09

Restart Apache and so let all changes take effect:

/etc/init.d/apache2 stop
/etc/init.d/apache2 start

Try to access http://localhost/index.html and check if message appear.

Install PHP5.2

First of all, unpack the PHP tarball:

cd /usr/local/src/
tar zxvf php-5.2.6.tar.gz
cd /usr/local/src/php-5.2.6

You should check all available parameter with:

./configure --help

Before start the configuration, I would like to give you some suggested combination of parameters. E.g.:

  --with-apxs2=/usr/local/apache2/bin/apxs \
  --with-config-file-path=/usr/local/apache2/conf \
  --enable-sigchild \
  --enable-bcmath \
  --with-bz2 \
  --enable-calendar \
  --with-curl \
  --enable-dba \
  --enable-exif \
  --enable-ftp \
  --with-gd \
  --with-gettext \
  --with-imap \
  --with-imap-ssl \
  --with-kerberos \
  --enable-mbstring \
  --with-mcrypt \
  --with-mime-magic=/usr/share/file/magic.mime \
  --with-openssl \
  --enable-shmop \
  --enable-soap \
  --enable-sockets \
  --enable-sqlite-utf8 \
  --enable-sysvmsg \
  --enable-wddx \
  --enable-zip \
  --with-zlib \

Moreover, OCI8 and PDO_OCI should configuration as (assume you have install Oracle 11gR1 to /u01/app/oracle/product/11.1.0/db_1):

  --with-oci8=/u01/app/oracle/product/11.1.0/db_1 \
  --with-pdo-oci=/u01/app/oracle/product/11.1.0/db_1 \

So the complete PHP5.2 configuration command with OCI8 + PDO_OCI should be:

./configure \
  --with-apxs2=/usr/local/apache2/bin/apxs \
  --with-config-file-path=/usr/local/apache2/conf \
  --enable-sigchild \
  --enable-bcmath \
  --with-bz2 \
  --enable-calendar \
  --with-curl \
  --enable-dba \
  --enable-exif \
  --enable-ftp \
  --with-gd \
  --with-gettext \
  --with-imap \
  --with-imap-ssl \
  --with-kerberos \
  --enable-mbstring \
  --with-mcrypt \
  --with-mime-magic=/usr/share/file/magic.mime \
  --with-openssl \
  --enable-shmop \
  --enable-soap \
  --enable-sockets \
  --enable-sqlite-utf8 \
  --enable-sysvmsg \
  --enable-wddx \
  --enable-zip \
  --with-zlib \
  --with-oci8=/u01/app/oracle/product/11.1.0/db_1 \
  --with-pdo-oci=/u01/app/oracle/product/11.1.0/db_1 \

Next, build and install the PHP5:

make
make test
make install

Copy PHP's supplied initialization file:

cp /usr/local/src/php-5.2.6/php.ini-recommended /usr/local/apache2/conf/php.ini

Create a PHP configuration file for Apache as /usr/local/apache2/conf/extra/httpd-php5.conf and add the following lines:

#
# This next section will call PHP for .php, .phtml, and .phps files
#
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php-source .phps

#
# This is the directory containing php.ini
#
PHPIniDir "/usr/local/apache2/conf"

Retouch /usr/local/apache2/conf/httpd.conf and add this line to the end of file:

Include conf/extra/httpd-php5.conf

If a LoadModule line was not already inserted by the PHP install, add it too:

LoadModule php5_module        modules/libphp5.so

Also update the DirectoryIndex:

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml
</IfModule>

Create a testing file as /var/www/phpsysinfo.php with below content:

<?php print phpinfo(); ?>

Restart your Apache and test your PHP setup with http://localhost/phpsysinfo.php

Oracle specific fine tune

By default, Apache's user account and user group don't have privilege to access Oracle's resources, so we will need some hack:

adduser www-data oinstall

Next, Apache don't have the idea about where is the Oracle instance client, so we need to specify for it. Edit /usr/local/apache2/bin/envvars and add the following lines at the end of file:

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.1.0/db_1
export ORACLE_SID=AL32UTF8
export NLS_LANG=.AL32UTF8
unset TNS_ADMIN

Assume you have already activate your Oracle's HR user account from database AL32UTF8. Create /var/www/oci8.php with following content, access http://localhost/oci8.php, test if your OCI8 driver install correctly:

<?php
  $db_conn
= ocilogon("HR", "CHANGE", "//localhost.localdomain/AL32UTF8.localdomain", 'AL32UTF8');
 
$cmdstr = 'SELECT "LAST_NAME", "SALARY" FROM "HR"."EMPLOYEES"';
 
$parsed = ociparse($db_conn, $cmdstr);
 
ociexecute($parsed);
 
$nrows = ocifetchstatement($parsed, $results);
  echo
"<html><head><title>Oracle PHP Test</title></head><body>";
  echo
"<center><h2>Oracle PHP Test</h2><br>";
  echo
"<table border=1 cellspacing='0' width='50%'>\n<tr>\n";
  echo
"<td><b>Name</b></td>\n<td><b>Salary</b></td>\n</tr>\n";
  for (
$i = 0; $i < $nrows; $i++ ) {
    echo
"<tr>\n";
    echo
"<td>" . $results["LAST_NAME"][$i] . "</td>";
    echo
"<td>$ " . number_format($results["SALARY"][$i], 2). "</td>";
    echo
"</tr>\n";
  }
  echo
"<tr><td colspan='2'> Number of Rows: $nrows</td></tr></table><br>";
  echo
"<em>If you see data, then it works!</em><br>";
  echo
"</center></body></html>\n";
?>

Also, create /var/www/pdo_oci.php with following content, access http://localhost/pdo_oci.php, test if your PDO_OCI driver install correctly:

<?php
  $db_conn
= new PDO('oci:host=localhost.localdomain/AL32UTF8.localdomain;charset=AL32UTF8', 'HR', 'CHANGE');
 
$cmdstr = 'SELECT "LAST_NAME", "SALARY" FROM "HR"."EMPLOYEES"';
 
$stmt = $db_conn->query($cmdstr);
 
$results = $stmt->fetchAll();
 
$stmt = $db_conn->query("SELECT COUNT(*) AS nrows FROM ($cmdstr)");
 
$nrows = $stmt->fetch(PDO::FETCH_OBJ)->NROWS;
  echo
"<html><head><title>Oracle PHP Test</title></head><body>";
  echo
"<center><h2>Oracle PHP Test</h2><br>";
  echo
"<table border=1 cellspacing='0' width='50%'>\n<tr>\n";
  echo
"<td><b>Name</b></td>\n<td><b>Salary</b></td>\n</tr>\n";
  for (
$i = 0; $i < $nrows; $i++ ) {
    echo
"<tr>\n";
    echo
"<td>" . $results[$i]["LAST_NAME"] . "</td>";
    echo
"<td>$ " . number_format($results[$i]["SALARY"], 2). "</td>";
    echo
"</tr>\n";
  }
  echo
"<tr><td colspan='2'> Number of Rows: $nrows</td></tr></table><br>";
  echo
"<em>If you see data, then it works!</em><br>";
  echo
"</center></body></html>\n";
?>


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <h1> <h2> <h3> <h4> <h5> <h6> <em> <strong> <code> <del> <blockquote> <q> <sub> <p> <br> <ul> <ol> <li> <dl> <dt> <dd> <a> <b> <u> <i> <sup> <acronym> <pre> <img>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Images can be added to this post.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.