Archive

Posts Tagged ‘apache’

Configuring PHP with Oracle support on Oracle Enterprise Linux

November 17th, 2011 No comments

In case you need to run PHP with Oracle support this is how to do it with Oracle Enterprise Linux 5.x. I assume that Apache and PHP are already installed.

First you need to download the source of latest version of oci8 driver, here. Also you need to download and install the latest version of Oracle Instant Client Packages – Basic and SDK, here.

The next step is to install both packages on the system:

rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
rpm -ivh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm

 

After installing the instant client, you have to build the oci8:

tar xfzv oci8-1.4.6.tgz
cd oci8-1.4.6
phpize
./configure -with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib
make install

Module will be installed in PHP modules directory, which is /usr/lib64/php/modules/.

Edit php.init and add the following line to make oci8 driver to be loaded by PHP:
extension=oci8.so

After restarting the web server,  you now have Oracle support enabled in PHP. Oracle support could be tested from command line without restarting the web server, with this simple script:

cat > /tmp/oracle.php

<?php
$username = "scott";
$passwd = "tiger";
$db="(DESCRIPTION=
           (ADDRESS_LIST=
             (ADDRESS=(PROTOCOL=TCP)
               (HOST=192.168.8.36)(PORT=1521)
             )
           )
             (CONNECT_DATA=(SERVICE_NAME=orcl))
      )";
$conn = OCILogon($username,$passwd,$db);
if (!$conn)
{
    echo "Connection failed";
    echo "Error Message: [" . OCIError($conn) . "]";
    exit;
}
else
{
    echo "Connected!";
}

 

Running the script shows that it is connecting successfully to the database:

[root@app tmp]# php oracle.php
Connected!

 

There is also manual at PHP for installation and configuration of OCI8, which could be found here.

Regards,
Sve

Categories: linux, oracle Tags:

Running PHP 5.3.6 with Oracle support on Windows Server 2008 (64bit)

June 20th, 2011 1 comment

I was involved in a project for running a media portal with Apache/PHP and Oracle database and was asked to build the environment. As the title says it’s a Windows Server 2008 Standard edition (no enterprise, no failsafe) what’s more the licenses for Oracle Database were for Standard Editon for one server. I managed to create a HA environment for both Apache and Oracle Database, but this is another topic which I hope to describe later.

The problems which took me most time and efforts were user equivalence during Grid Infrastructure installation and running Apache/PHP with Oracle support.

In case you have installed PHP with Oracle support (enabled extension=php_oci8_11g.dll at php.ini) and does not see any OCI8 support in phpinfo(); or run in following errors during Apache startup:

The requested operation has failed!

OR

httpd.exe:
The application has failed to start because OCI.dll was not found.
Re-installing the application may fix the problem.

 

Then most probably you’re trying to run PHP (which is 32bit) with Oracle OCI library (which is 64bit). I had installed database binaries already on both machines and that’s why I had oci.dll in the PATH variable. Now PHP is trying to load my 64bit oci.dll library and fails, this could easily be determined with file command:
sve@angmar:/tmp$ file oci.dll
oci.dll: PE32+ executable for MS Windows (DLL) (GUI) Mono/.Net assembly
sve@angmar:/tmp$ file php.exe
php.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit

The solution was to download Oracle instant client 11.2 (32bit!) and put it for example in PHP home directory. Then the path has to be added to the environment variable PATH at first place. Now OCI8 support is enabled and Apache server is starting normally, also running file against new oci.dll shows following:

sve@angmar:/tmp$ file oci.dll
oci.dll: PE32 executable for MS Windows (DLL) (GUI) Intel 80386 32-bit

 

Regards,
Sve

Categories: oracle, windows Tags: ,