Nov 11, 2011

Ubuntu : Apache, PHP & Oracle with oci8 enable Installation



It's been a while since I need to program PHP with connection to an Oracle database.  Usually, I would prefer to design my system to use MySQL or postgreSQL to link up with PHP as a database.  But I cannot exclude myself to have to code a PHP system which need to connect to an Oracle DB by a client specific request.

So, as I'm lurking around the Google street to have a good and working guide on how to setup PHP to be able to connect to Oracle - I did found out that there are not many tutorial available on blogs and forums on a working step-by-step Apache, PHP and Oracle installation guide with an oci8 extension enable.


So here is my version of tutorial and a step-by-step on solving the issues I mention above:

  1. Firstly, I need to mention to Negative Zero's lovely readers that this tutorial will be using a Ubuntu way of installing all application.  And surely, there will be no compiling things in order to follow this tutorials.
  2. This tutorial is tested and specifically written for Ubuntu Oneiric 11.10 version of Ubuntu.  Those who is using an older version or maybe a newer version of Ubuntu, any errors or problems you do encounter while following this tutorials, kindly please let me know by leaving a comment.
  3. So to make our first move, we need to APT-GET a few packages which will be Apache2, php5. Open up your terminal and run this command in your terminal :
    sudo apt-get install apache2 php5 build-essential
  4. After finish installing Apache web server and PHP 5 package from repositories, now we need to add a new repositories to install Oracle Express Edition on our machine.  To do this, you need to add Oracle official repositories for debian unstable repository which listed in Oracle official website.  Type in this command in your terminal (This command will open a terminal based editor nano with a root privilege:
    sudo nano /etc/apt/source.list.d/oracle.list
  5. Next, paste the code below into nano editor and press CTRL+X to save and exit the editor.deb http://oss.oracle.com/debian unstable main non-free
  6. Once the nano exited, the next step is to import the Oracle GPG key, update your source and install the Oracle Express Edition. Follow steps below to accomplish this:
    wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle -O- | sudo apt-key add -
    sudo apt-get update
    sudo apt-get install oracle-xe
  7. After finish setting-up the Oracle Express Edition database on your Ubuntu, now we need to enable the oci8 extension in order to connect our PHP codes to connect with Oracle-XE with success. 
  8. Before moving to the installation of oci8, we need to prepare our system environment variable, download required instant client from Oracle and place the required files in the right folder.  Please download this Instant Client Basic and Instant Client SDK from linux instant-client files list.
  9. Once download finished, we need to set the environment for Oracle.  This step is required for our oci8 installation which we will install after this steps.  To set required environment variable, please follow steps below one-by-one ( please notice that lines with # symbols is a notes on what to do.  If you are a lazy person, please don't copy and paste lines with # and ranting about failure to accomplish your goals in comments ) :
    # Edit /etc/environment files
    sudo nano /etc/environment
    # Paste text below at the end of the files. Then save and exit nano by
    # CTRL+X button

    LD_LIBRARY_PATH="/usr/local/lib/instantclient_11_2"
    TNS_ADMIN="/usr/local/lib/instantclient_11_2"
    ORACLE_BASE="/usr/local/lib/instantclient_11_2"
    ORACLE_HOME=$ORACLE_BASE
  10. Now we are set to install oci8.  To start the installation, follow steps listed below:
    cd /usr/local/lib/
    sudo unzip /path/to/Instant/Client/Basic-that-you-downloaded-on-step-8
    sudo unzip /path/to/Instant/Client/SDK-that-you-downloaded-on-step-8
    cd instantclient_11_2
    sudo ln -s libclntsh.so.11.1 libclntsh.so
  11. Now, final steps on installing oci8 :
    sudo pecl install oci8
  12. You will be prompt to state location for Oracle library, when this action trigger - paste the location below:
    instantclient,/usr/local/lib/instantclient_11_2/
  13. Now, all installation has been completed. Last thing to do before restarting your Apache webserver to load the new settings on enabling oci8 extension.  Create a new file in /etc/php5/conf.d/oci8.ini and/or paste code below:
    # Open nano and create oci8.ini file in /etc/php5/conf.d folder
    sudo nano /etc/php5/conf.d/oci8.ini
    # Paste line below in new created oci8.ini file.
    extension=oci8.so
    # Save and exit nano editor by pressing CTRL+X button.
  14. Now restart your Apache for the new configuration to take place.  
After finish following this step-by-step tutorial, please make sure that oci8 is enabled in phpinfo() list.  If it does not listed in phpinfo() - then you might have done something wrong during step 1 to 13.  Please recheck your steps and read my instruction clearly before copying and pasting line of codes in your terminal.  Be a geek, don't be a leech.  Start to read on guides, and stop from blindly copy & paste junk from blogs and internet.

But if any error occurs by my mistyping mistakes or maybe by a dependencies error due to outdated steps in this tutorial, please alert me by commenting either by FB comments or Blogger comments.


Thank you for your unbelievable support on Negative Zero - Permission to read and write blog for nearly 4 years. Don't forget to like Negative Zero on Facebook.
Blogirific.com Blog Directory





Post(s) you might like to read :

Comments
0 Comments

0 comments:

Post a Comment