Getting PHP to use Oracle connectors on CentOS 5.2Oracle have released a great paper OCI8 & current PHP sourceThe manual refers to PHP 5.2.8, which is beyond the version CentOS 5.2 ships, and this does make a difference. The source RPMs for CentOS 5.2's PHP cannot be used, because Oracle's OCI8 extension is not compatible with that version of PHP (5.1.x). So, best bet is to grab the configure parameters from another vanilla CentOS 5.2 install (phpinfo will list them), in order to apply them later. (Or from the same machine, if there's a CentOS PHP version running on it.) But first, let's get the necessary files (you need an account with Oracle, which is for free). From this website $ rpm -Uvh oracle-instantclient11.1-basic-11.1.0.7.0-1.i386.rpm $ rpm -Uvh oracle-instantclient11.1-devel-11.1.0.7.0-1.i386.rpm Once this is done, we need the latest PHP sources, downloadable from here ./configure --build=i686-redhat-linux-gnu --host=i686-redhat-linux-gnu --target=i386-redhat-linux-gnu \ --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc \ --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/libexec --localstatedir=/var \ --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --cache-file=../config.cache \ --with-libdir=lib --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --disable-debug --with-pic \ --disable-rpath --without-pear --with-bz2 --with-curl --with-exec-dir=/usr/bin --with-freetype-dir=/usr \ --with-png-dir=/usr --enable-gd-native-ttf --without-gdbm --with-gettext --with-gmp --with-iconv \ --with-jpeg-dir=/usr --with-openssl --with-png --with-pspell --with-expat-dir=/usr --with-pcre-regex=/usr \ --with-zlib --with-layout=GNU --enable-exif --enable-ftp --enable-magic-quotes --enable-sockets \ --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-track-vars --enable-trans-sid --enable-yp \ --enable-wddx --with-kerberos --enable-ucd-snmp-hack --with-unixODBC=shared,/usr --enable-memory-limit \ --enable-shmop --enable-calendar --enable-dbx --enable-dio --with-mime-magic=/usr/share/file/magic.mime \ --without-sqlite --with-libxml-dir=/usr --with-xml --with-system-tzdata --with-apxs2=/usr/sbin/apxs \ --without-mysql --without-gd --without-odbc --disable-dom --disable-dba --without-unixODBC --disable-pdo \ --disable-xmlreader --disable-xmlwriter \ --with-oci8=instantclient,/usr/lib/oracle/11.1/client/lib \ --enable-sigchild The latter two parameters are related to the Oracle OCI8. Most likely, configure will complaiin about loads of missing dependencies. This should fix most of them, if not all: yum install bzip2-devel curl-devel db4-devel expat-devel \ gmp-devel aspell-devel httpd-devel libjpeg-devel libpng-devel \ pam-devel libstdc++-devel openssl-devel sqlite-devel zlib-devel \ pcre-devel libtool gcc-c++ krb5-devel libc-client-devel \ cyrus-sasl-devel openldap-devel mysql-devel postgresql-devel \ unixODBC-devel libxml2-devel net-snmp-devel libxslt-devel \ libxml2-devel ncurses-devel gd-devel freetype-devel If there are other dependencies missing, use yum to install the -devel RPMs. It's all there, so no need to download anything else from third parties (which we do want to avoid anyway, because it makes updating more difficult). Before we can go ahead compiling, we need to update the linker cache: /usr/lib/oracle/11.1/client/lib/ Once, that's done, refresh the linker cache: ldconfig -v No we can finally go ahead with make && make install Afterwards restart the apache service httpd restart Ideally, that should be it. Apache configurationPHP does not know about the custom RedHat/CentOS configuration structure in /etc/httpd. So if there was PHP installed already, you may need to comment out the LoadModule directive in /etc/httpd/conf/httpd.conf, because it's already in /etc/httpd/conf.d/php.conf. If PHP was not installed before, we need to create the aforementioned file. Just create /etc/httpd/conf.d/php.conf with this content:
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
LoadModule php5_module modules/libphp5.so
#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps
And afterwards service httpd restart will get you going. Is OCI8 there?Now create a simple info.php file somewhere, where Apache can access it:
<?php
phpinfo();
?>
... and call it in your browser. The OCI8 section should be somewhere there. That's it. The PHP-part is done! Setting up DSNsThe paper I mentioned before gives a lot of examples how to configure Oracle. Also it introduces Oracle Express If you do have Oracle access, you can start straight away setting up /etc/tnsnames.ora. This is the file/location, where Oracle/OCI will always look for the DSN settings. Examples can be found in the paper, I mentioned in the beginning. That'll be it. Well done! |
Shortcuts |