I need to install PDO_OCI in ubuntu machine, there is no default package that I could install with apt-get.
There are a lot of tutorials showing how to do it, but when I follow them, I have problems related to compilation (configure, make,...)
Here what I did:
I followed this Tutorial to install instant client
Install oci8
pecl install oci8
I get error:
error: oci.h not found
Install PDO_OCI
mkdir -p /tmp/pear/download/ cd /tmp/pear/download/ pecl download pdo_oci phpize ./configure –with-pdo-oci=instantclient,/usr,11.2
error:
pdo_driver.h not found ...
Please do you have any serious tutorial that works perfectly on UBUNTU 12.04?
installing with PECL is deprecated, don't use it. Here is a good tutorial step by step how to install PDO_OCI and Oracle instant client on linux machine: http://shar.lt/linux-install-oracle-instant-client-php-pdo_oci-library/
The PDO, PDO_OCI extensions from
pecl install
are obsolete because latest PHP version has them built-in its core & installation these extensions by this way mostly failed.I've spent a lot of time to try to do this following several approach with no luck, and finally find it out by myself a clean way to do this: compile & install the extensions from PHP source.
During the compilation, there are some tricks as well, I've described the process in detail in my post: https://medium.com/@thucnc/how-to-install-php5-pdo-oci-oci8-and-other-extensions-for-ubuntu-f405eadfe784
Short steps are listed here:
ORACLE_HOME
environment variableDownload & compile PDO_OCI (and OCI8 if needed) form PHP source packages, there are some tricks that you need to applied here, including:
sudo ln -s /usr/include/php5/ /usr/include/php
and edit the Makefile:
EXTRA_INCLUDES = -I/usr/include/oracle/11.2/client64
Enable the extensions and restart web server
This has been tested for Debian 7.6 as well
Hope this helps.
The answer is a replication of this article (in Russian) which is in turn based on this post with some corrections. After several days of fruitless search it worked smoothly for me.
Prerequisites:
You should have administrator privileges
You should have php5 installed with the following packages:
You should have libaio1 library installed:
Installation of Oracle Instant Client
Dowload Oracle instant client for your processor architecture and OS from Oracle website (oracle.com/technetwork/database/features/instant-client/index-097480.html).
For Linux there are 2 options of instant client: RPM package for Linux, CentOS, Fedora, Red Hat Enterprise Linux, Mandriva Linux, SUSE Linux, etc. ZIP archive — for all others not supporting RPM.
There are 2 files to be downloaded:
instantclient-basic — Oracle instant client itself
instantclient-sdk — set of libraries for application development
Create directory for Oracle instant client ( /opt directory reserved for software extensions suits well for this purpose):
Move downloaded files to /opt/oracle and switch to destination folder (assuming that you downloaded "zip" archives to your user "downloads" directory):
Extracting downloaded archives:
Finally we have
instantclient_11_2
directory created in/opt/oracle
for Oracle instant client 11.2.0.2.0. Rename this directory toinstantclient
(pay attention to version number) and switch to it:Next we'll have to create several additional directories and symlinks (pay attention to version number):
Create configuration file containing name of directory where Oracle instant client libraries are to be searched for and enable it:
As far as there is not directory
/usr/include/php
in Ubuntu, but the client is still searchin for it, we'll create symlink to it's equivalent - php5:Installation of OCI8
After previous actions oci8 extension is installed with
pecl
command:you will be prompted for path to Oracle instant client, respond with:
Creating extension connection file:
Installation of PDO_OCI
For installation of PDO_OCI download it from pear repository (pear.php.net).
Update pear packages list:
Download and place archive to temp directory:
Extract archive contents:
Here we'll have to ammend
config.m4
file as it does not contain information on our version of Oracle instant client. Open the file and add changes marked with "+" (pay attension to version number):Below is the
diff
of 2 files:Prepare environment for php extension with
phpize
(php.net/manual/ru/install.pecl.phpize.php) command:Configure package installer and install package (pay attention to version number):
Create connection file for it:
Restart apache and check if extensions were installed:
This guide might help to compile the pdo_oci module from source, since PECL version is now obsolete. I wrote the original post for CentOS 6.6, PHP v5.3.3 and Oracle Instant client v.12.1, but it should be easy to apply it for your case also.
Install PHP development package
Download PHP source code
Prepare PDO_OCI for compilation
Make sure that you have $ORACLE_HOME environment variable set. In my case it was pointing to /usr/lib/oracle/12.1/client64
Browse to folder where extension source files are located:
Since we are running an Oracle client version 12.1, which is not supported out-of-box by the extension, we need to do some hacking. Our Instant Client version number needs to be added to config.m4 file, otherwise configure will fail with the following error message
Open the config.m4 file and look for
SUPPORTED_LIB_VERS
(line 5 or so), add12.1
to the list of versions. Also findcase $PDO_OCI_VERSION in
line (could be line 134) and add|12.1
to the list of versions below it. Save the file and that is all we need here.Prepare, configure and make the extension
Now, make will most probably fail complaining that it cannot find the Oracle header files, e.g. oci.h. That is because, unless you installed the Oracle server, or Instant client in developer mode, the files do not exist on the server.
Go to oracle.com, Instant Client Downloads for Linux page and get the Instant client SDK package for your version: Instant Client Downloads for Linux
In my case I downloaded this file: http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
Unpack the file in any location of your choice. The header files we need are in sdk/include folder. Copy all these files to the include folder of the extension: /usr/local/src/php_source/php-5.3.3/ext/pdo_oci/include
Now the make should pass:
As the end result you will get a compiled pdo_oci.so module in /modules subfolder of your extension directory: /usr/local/src/php_source/php-5.3.3/ext/pdo_oci/modules/pdo_oci.so
Move and enable the compiled module
Find out where PHP stores it's extensions on the server
Copy the extension (pdo_oci.so) to that directory.
Now there are a couple of ways to enable the module. One is by including it in the main php.ini file, but in my case I created a separate .ini file in a folder where other .ini files of other modules are residing and which are included by PHP upon startup.
So I created a file /etc/php.d/pdo_oci.ini with the following contents:
Alternatively the same line can be added to your php.ini file.
Restart Apache and check
In case you have PHP CLI installed, you can check the list of loaded modules, otherwise create a PHP file with phpinfo() in it and check the outputs. If you see PDO_OCI in the output - congratulations!
Credits
Thanks to Mattias Geniar for the original post on how to compile PHP extensions from source: https://ma.ttias.be/how-to-compile-and-install-php-extensions-from-source/