Connecting an Oracle Database via PHP, requires a not easy procedure. The bash scripts OracleViaPHP.sh and TNSconnect.sh will automate the set up process for you.
The scripts are tested on a virtual machine running OS Linux Ubuntu Server 8.04.1 i386 created on a Mac OS X running Leopard 10.5.3. OracleViaPHP.sh will install and configure Apache2, PHP5, the Oracle Client v10.2 and the OCI8 and TNSconnect.sh will create the file tnsnames.ora to connect the Oracle DB. The scripts should also work on Ubuntu 9.x.
1. Download Ubuntu Server 8.04.1 from www.ubuntu.com
2. Download from the Oracle website the Oracle Client for Linux x86 Version 10.2.0.4 and the SDK:
– the Oracle Client ‘Instant Package – Basic Lite’ [oracle-instantclient-basiclite-10.2.0.4-1.i386.zip]
– the Oracle Client ‘Instant Package – SDK’ [oracle-instantclient-devel-10.2.0.4-1.i386.zip]
3. Download the bash scripts OracleViaPHP.sh and TNSconnect.sh. Last version can be found in the script page.
4. Install Ubuntu Server 8.04.1
1. Set a root password and log in as root
# sudo passwd
# su –
2. Copy the files oracle-instantclient-basiclite-10.2.0.4-1.i386.zip, oracle-instantclient-devel-10.2.0.4-1.i386.zip, OracleViaPHP.sh and TNSconnect.sh into the /root directory.
3. Enter the /root directory and execute the installation script.
# cd /root
Post-Installation: [Steps Required]
1. Make sure you know SID, SERVER and PORT of the server you want to connect.
2. Execute the script TNSconnect.sh
# cd /root
3. Type: Oracle SID, Oracle Server, Oracle Server Port, Oracle Database Username, Oracle Database Password.
1. Connecting http://your_ip_address/info.php you should get the PHP info page showing the module oci8 installed.
2. Connecting http://your_ip_address/test.php you should be able to connect the Oracle DB you defined.
If you get the error:
Warning: ocilogon() [function.ocilogon]: ORA-12154: TNS:could not resolve the connect identifier specified in /var/www/test.php on line 2
Could not connect to Oracle database!
It is possible that:
1. You typed the Oracle Server details in a wrong way. You can edit manually this information in the files /opt/oracle/tns/tnsnames.ora and /var/www/test.php
2. The permission to the file /opt/oracle/tns/tnsnames.ora are not right. You can to execute the following command:
# chmod 777 /opt/oracle/tns/tnsnames.ora
3. The environment variables in the file /etc/init.d/apache2 are not defined properly. Make sure that the file /etc/init.d/apache2 contains at the beginning the following string:
ENV=”env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin
If you get the error:
/usr/bin/ld: skipping incompatible /opt/oracle/instantclient_10_2/libclntsh.so when searching for -lclntsh
/usr/bin/ld: cannot find -lclntsh
collect2: ld returned 1 exit status
make: *** [oci8.la] Error 1
ERROR: `make' failed
it’s possible that your server has a 64-bit architecture. You will need to download from the Oracle website the Oracle Client and the SDK package for Linux 64-bit architecture and manually unzip the files in the directory /opt/oracle/instantclient_10_2.
Your comment, error reports and improvement requests are always welcome ;D