Before we begin, make sure you have the following
- A working instance of LAMP ( Linux, Apache, php and MySQL ) - at least Apache and PHP
- Root privileges
- A file called phpinfo.php( in your webroot which has phpinfo() ) to verify OCI8 after installation
You can install LAMP very easily with tasksel : sudo apt-get install tasksel -> tasksel ->choose LAMP server
We will need 2 packages from Oracle ( 32 or 64 bit according to your machine ) - current Version 11.2.0.3.0 – zip versions
- You can get the 2 downloads ( 32-bit ) from here http://www.oracle.com/technetwork/topics/linuxsoft-082809.html
- Instant Client Package – Basic: All files required to run OCI, OCCI, and JDBC-OCI applications
- Unzip all files in this to a directory called /opt/oracle_instantclient ( of-course you can put it anywhere you like )
- Instant Client Package – SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client
- Unzip this into the same directory /opt/oracle_instantclient
- Your /opt/oracle_instantclient directory must now contain all files from Instant Client Package – Basic and an SDK directory from Instant Client Package – SDK
- Next we need to create some symbolic links to “.so” files – you will see a file called libclntsh.so.version in /opt/oracle_instantclient directory. In my case the file name is libclntsh.so.11.1. We will create a symbolic link named libclntsh.so to the file libclntsh.so.11.1 in the same directory using the command ln -s libclntsh.so.11.1 libclntsh.so
- Next we will install the php5-dev package command sudo apt-get install php5-dev
- Next we will install the package libaio using the command sudo apt-get install libaio-dev
- Then we install pear package using sudo apt-get install php-pear
- Next, we will install the oci8 extension using sudo pecl install oci8
- This will ask for Oracle Home Directory – give the path of the instant client instantclient,/opt/oracle_instantclient
- In the above, we are telling pecl that its an instantclient and then giving the path to the instantclient directory
- If the installation is successful, you should see messages like “Build Process completed successfully”
- Add the oracle oci8.so to php.ini using
- sudo echo “extension=oci8.so” >> /etc/php5/apache2/php.ini
- sudo echo “extension=oci8.so” >> /etc/php5/cli/php.ini
- ( Tip from Omar ) An alternative is to add this to the oci8.ini file using the command sudo echo “extension=oci8.so” > /etc/php5/conf.d/oci8.ini
- Restart apache using service apache2 restart
- Open a web browser and navigate to the phpinfo file ( in my case it is localhost/phpinfo.php )
- Search for oci8 and you should find oci8 block with variables ( this means you have successfully compiled PHP with the oci8 extension )
- Next step is to test connecting to an oracle instance using oci_connect();
- Contact your Oracle DBA and get the following information hostname, port, service name, service type, username, password and then try out an example from http://www.php.net/manual/en/function.oci-connect.php
- If you get the error, oci_connect() is not defined, then something went wrong. Try looking at apache error logs or use php -v
Posting Komentar