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?
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:
- Download & install Oracle instant Client, then export
ORACLE_HOME
environment variable
Download & 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:
sudo apt-get install php5 php5-dev php-pear php5-cli
sudo pecl install pdo
You should have libaio1 library installed:
sudo apt-get install libaio1
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):
sudo mkdir -p /opt/oracle/
Move downloaded files to /opt/oracle and switch to destination folder (assuming that you downloaded "zip" archives to your user "downloads" directory):
sudo mv ~/downloads/instantclient-*.zip /opt/oracle/
cd /opt/oracle/
Extracting downloaded archives:
sudo unzip instantclient-basic-*-*.zip
sudo unzip instantclient-sdk-*-*.zip
Finally we have instantclient_11_2
directory created in /opt/oracle
for Oracle instant client 11.2.0.2.0. Rename this directory to instantclient
(pay attention to version number) and switch to it:
sudo mv instantclient_11_2 instantclient
cd instantclient
Next we'll have to create several additional directories and symlinks (pay attention to version number):
sudo ln -s /opt/oracle/instantclient/libclntsh.so.* /opt/oracle/instantclient/libclntsh.so
sudo ln -s /opt/oracle/instantclient/libocci.so.* /opt/oracle/instantclient/libocci.so
sudo ln -s /opt/oracle/instantclient/ /opt/oracle/instantclient/lib
sudo mkdir -p include/oracle/11.2/
cd include/oracle/11.2/
sudo ln -s ../../../sdk/include client
cd -
sudo mkdir -p lib/oracle/11.2/client
cd lib/oracle/11.2/client
sudo ln -s ../../../ lib
cd -
Create configuration file containing name of directory where Oracle instant client libraries are to be searched for and enable it:
echo /opt/oracle/instantclient/ | sudo tee -a /etc/ld.so.conf.d/oracle.conf
sudo ldconfig
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:
sudo ln -s /usr/include/php5 /usr/include/php
Installation of OCI8
After previous actions oci8 extension is installed with pecl
command:
sudo pecl install oci8
you will be prompted for path to Oracle instant client, respond with:
instantclient,/opt/oracle/instantclient
Creating extension connection file:
echo "; configuration for php oci8 module" | sudo tee /etc/php5/conf.d/oci8.ini
echo extension=oci8.so | sudo tee -a /etc/php5/conf.d/oci8.ini
Installation of PDO_OCI
For installation of PDO_OCI download it from pear repository (pear.php.net).
Update pear packages list:
sudo pecl channel-update pear.php.net
Download and place archive to temp directory:
sudo mkdir -p /tmp/pear/download/
cd /tmp/pear/download/
sudo pecl download pdo_oci
Extract archive contents:
sudo tar xvf PDO_OCI*.tgz
cd PDO_OCI*
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):
sudo vim config.m4
Below is the diff
of 2 files:
***************
*** 7,12 ****
--- 7,14 ----
if test -s "$PDO_OCI_DIR/orainst/unix.rgs"; then
PDO_OCI_VERSION=`grep '"ocommon"' $PDO_OCI_DIR/orainst/unix.rgs | sed 's/[ ][ ]*/:/g' | cut -d: -f 6 | cut -c 2-4`
test -z "$PDO_OCI_VERSION" && PDO_OCI_VERSION=7.3
+ elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.11.2; then
+ PDO_OCI_VERSION=11.2
elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.10.1; then
PDO_OCI_VERSION=10.1
elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.9.0; then
***************
*** 119,124 ****
--- 121,129 ----
10.2)
PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)
;;
+ 11.2)
+ PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)
+ ;;
*)
AC_MSG_ERROR(Unsupported Oracle version! $PDO_OCI_VERSION)
;;
***************
Prepare environment for php extension with phpize
(php.net/manual/ru/install.pecl.phpize.php) command:
sudo phpize
Configure package installer and install package (pay attention to version number):
sudo ./configure --with-pdo-oci=instantclient,/opt/oracle/instantclient/,11.2
sudo make
sudo make install
Create connection file for it:
echo "; configuration for php PDO_OCI module" | sudo tee /etc/php5/conf.d/pdo_oci.ini
echo extension=pdo_oci.so | sudo tee -a /etc/php5/conf.d/pdo_oci.ini
Restart apache and check if extensions were installed:
sudo /etc/init.d/apache2 restart
php -m
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
$ apt-get install php-devel
Download PHP source code
$ cd /usr/local/src
$ mkdir php_source
$ cd php_source/
$ wget http://museum.php.net/php5/php-5.3.3.tar.gz
$ gunzip php-5.3.3.tar.gz
$ tar xvf php-5.3.3.tar
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:
$ cd php-5.3.3/ext/pdo_oci
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
Oracle version... configure: error: Oracle required OCI8 libraries not found under /usr/lib/oracle/12.1/client64
Open the config.m4 file and look for SUPPORTED_LIB_VERS
(line 5 or so), add 12.1
to the list of versions. Also find case $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
$ phpize
$ ./configure
$ make
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:
$ make
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
$ php -i | grep extension_dir
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:
; Enable pdo_oci extension module
extension=pdo_oci.so
Alternatively the same line can be added to your php.ini file.
Restart Apache and check
$ /etc/init.d/httpd restart
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!
$ php -m
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/