Published on Feb 2, 2011

Compiling PHP 5.3.3 under CentOS 5.5 with Oracle instantclient 10.2 and OCI8

Centos 5.5 is distributed with PHP 5.1.6 and will not be upgraded for any future CentOS 5.X distribution :-( However, many developers need to use newer version of PHP. If PHP 5.1.6 is not sufficient enough for you, you have two ways how to upgrade - either via repositaries maintained by 3rd party (Jason Jitka, Remi) or compile PHP from sources yourself. If you also need to compile with support for oracle database (which is one of most difficult PHP extensions to make it work), you may find that easiest way is to compile PHP yourself. Here is simpliest way how to do that.

NOTE:
Steps bellow are applicable to PHP 5.3.3 as well as for PHP 5.3.4. Click here to review full list of PHP 5.3.4 compilation options.

STEP 1: Download PHP sources, Oracle instantclient for linux with SDK and sources for OCI8

  1. download PHP sources from http://sk.php.net/get/php-5.3.3.tar.gz/from/a/mirror
  2. download OCI8 (oci8-1.4.3.tgz) extension from http://pecl.php.net/package/oci8/download/
  3. download oracle linux 32-bit distributions from http://www.oracle.com/technetwork/topics/linuxsoft-082809.html:
    • instantclient-basic-linux32-10.2.0.5.0.zip (34 MB)
    • instantclient-sdk-linux32-10.2.0.5.0.zip (604 kB)
      Please note, that this compilation only works with oracle instant client 10.2. Instantclient 11 proved to have incompatibility issues with OpenLDAP due to the "Redeclared headers" error during compilation time.
  4. If you are installing on 64-bit machine you can download oracle instantclient (basic + SDK) for linux64 from http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

Place all downloaded archives into /usr/local/src/. This is default location for keeping non-system source files.

STEP 2: Install apache server with mod_ssl (skip this step if already installed)

yum install httpd-devel mod_ssl httpd

Start webserver:
service httpd start

Optionally set it to autostart during boot:
chkconfig --level 345 httpd on

STEP 3: Install required PHP extensions and needed PHP tools:

yum install flex libc-client-devel libc-client autoconf gcc-c++ [... tools]
yum install krb5-libs krb5-workstation krb5-devel krb5-server krb5-devel pam-devel [... kerberos]
yum install libmhash-devel libmcrypt-devel [... cryptography]
yum install libxml2-devel libxslt-devel expat-devel [... xml, xsl]
yum install zlib-devel bzip2-devel [... compression]
yum install curl-devel openldap-devel libtidy-devel
yum install t1lib-devel freetype-devel libpng-devel libjpeg-devel libXpm-devel [... GD2]
yum install postgresql-devel mysql-devel [... database clients]

Database servers:
yum install postgresql postgresql-server (if you want postgreSQL server)
yum install mysql mysql-server (if you want mySQL server)

You may also need::
yum install php-devel [... will install phpize]

STEP 4: Prepare Oracle instantclient with headers and compile OCI8 extension:

Create and run script in /usr/local/src/compile-oci8-instantclient.sh with following content:


clear

############################################
# PREPARE SOURCES - all should be copied into /usr/local/src/ with extension [gz|tgz]
# HOWTO:
#		http://www.php.net/manual/en/oci8.installation.php
#		http://ubuntuforums.org/archive/index.php/t-92528.html
#		http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ape.htm
############################################
#
# IMPORTANT - Dont use instantclient 11g version!
# It has installation compatability issues with OpenLDAP! (redeclared headers)
#
# Install instantclient 10.2.0.5, download instantclient+sqlplus+sdk for linux32 x86 from:
# http://www.oracle.com/technetwork/topics/linuxsoft-082809.html
#
# Or download 64bit linux basic client + SDK from:
# http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
# (you may rename filenames apropriately to work with this shell script)
#
# must have in the same directory as this script:
# instantclient-basic-linux32-10.2.0.5.0.zip
# instantclient-sdk-linux32-10.2.0.5.0.zip
# oci8-1.4.3.tgz

# temporary directory to collect compilation output
TEMP="temp"
#rm -r $TEMP >& /dev/null
mkdir $TEMP >& /dev/null
chmod -R 644 $TEMP

# log filename
STAMP=`date +%Y-%m-%d-%H-%M`
LOG="./$TEMP/compilation-$PHP.$STAMP.log"
echo "LOG - Compilation Results" > $LOG

# get current working directory path
CURRENTDIR=`pwd`

# first we will need to unzip instant client
ORA_CLIENT="instantclient-basic-linux32-10.2.0.5.0.zip"
ORA_CLIENT_SDK="instantclient-sdk-linux32-10.2.0.5.0.zip"
ORA_CLIENT_DIR=/usr/local/oracle/

# remove previous directory
rm -r $ORA_CLIENT_DIR >& /dev/null

# create directory and unzip instant client
mkdir $ORA_CLIENT_DIR
cp $ORA_CLIENT $ORA_CLIENT_DIR
cp $ORA_CLIENT_SDK $ORA_CLIENT_DIR
cd $ORA_CLIENT_DIR
unzip -o $ORA_CLIENT
unzip -o $ORA_CLIENT_SDK
rm $ORA_CLIENT
rm $ORA_CLIENT_SDK

# create symlink:
SUBDIRDIR=`ls`
cd $SUBDIRDIR
ln -s libclntsh.so.10.1 libclntsh.so
ln -s libocci.so.10.1 libocci.so

# return to current working directory
cd $CURRENTDIR

##################################################################

# now we will compile oci8 1.4.3
EXTENSION="oci8-1.4.3"
# untarred directory name
EXTENSIONDIR=$EXTENSION

# temporary directory to collect compilation output
TEMP="temp"
#rm -r $TEMP >& /dev/null
mkdir $TEMP >& /dev/null
chmod -R 644 $TEMP

# log filename
STAMP=`date +%Y-%m-%d-%H-%M`
LOG="./$TEMP/compilation-$EXTENSION.$STAMP.log"
OPTIONS="./$TEMP/config-options-$EXTENSION.log"
echo "LOG - Compilation Results" > $LOG

echo "=========================" | tee -a $LOG
echo "Defining resources... done." | tee -a $LOG
echo "=========================" | tee -a $LOG

#############################################
# clean up previosly compiled files
#############################################

# if there has ben previously PHP compilation, we should clean up previously compiled files:
if [ -d "$EXTENSIONDIR" ]
then
	echo "=========================" | tee -a $LOG
	echo "Cleaning up previous compilation.." | tee -a $LOG
	echo "=========================" | tee -a $LOG
	cd ./$EXTENSIONDIR
	make clean > ./.$LOG
	cd ..
fi

#############################################
# Untar sources
#############################################

echo "=========================" | tee -a $LOG
echo "Untaring sources.." | tee -a $LOG
echo "=========================" | tee -a $LOG

rm -r $EXTENSIONDIR
tar -zxvf $EXTENSION.tar.gz

############################################
# COMPILE
############################################

cd $EXTENSIONDIR

phpize
# If you cannot run phpize, install:
# yum install php-devel

echo "$EXTENSION - running config.." >> ./.$LOG
./configure --with-oci8=shared,instantclient,${ORA_CLIENT_DIR}instantclient_10_2 >> ./.$LOG

echo "$EXTENSION - running make.." >> ./.$LOG
make >> ./.$LOG

#echo "$EXTENSION - running make test.." >> ./.$LOG
#make test >> ./.$LOG

echo "$EXTENSION - running make install.." >> ./.$LOG
make install >> ./.$LOG

cd ..

echo "Completed compilation of $EXTENSION in $EXTENSIONDIR. Check logs in [$LOG]"

# ADD extension into /etc/php/php.ini:
# extension=oci8.so

STEP 5: Compile PHP 5.3.3

Create and run script in /usr/local/src/compile-php.sh with following content:


# install following packages from Centos repos:
#=============================================
# yum install autoconf httpd-devel mod_ssl gcc-c++ pam-devel krb5-libs krb5-workstation krb5-devel krb5-server krb5-devel libmhash-devel libmcrypt-devel
# yum install aspell-devel mhash-devel t1lib-devel freetype-devel libpng-devel libjpeg-devel ncurses-devel libxml2-devel libxslt-devel
# yum install openldap-devel libtool bzip2 pcre-devel zlib-devel openssl-devel libstdc++-devel curl-devel bzip2-devel
# yum install php-devel libc-client libc-client-devel libtidy-devel
#=============================================
# before compiling PHP you must install oci8 with oracle instant client!

clear

# set default place for PHP INI configuration
PHPINI="/etc/php"

# download from http://sk.php.net/get/php-5.3.3.tar.gz/from/a/mirror
PHP="php-5.3.3"

# temporary directory to collect compilation output
TEMP="temp"
#rm -r $TEMP >& /dev/null
mkdir $TEMP >& /dev/null
chmod -R 644 $TEMP

# log filename
STAMP=`date +%Y-%m-%d-%H-%M`
LOG="./$TEMP/compilation-php.$STAMP.log"
echo "LOG - Compilation Results" > $LOG

echo "=========================" | tee -a $LOG
echo "Defining resources and cleaning up previous compilation..." | tee -a $LOG
echo "=========================" | tee -a $LOG

#############################################
# clean up previosly compiled files
#############################################

# clean up previously compiled files:
if [ -d "$PHP" ]
then
	echo "=========================" | tee -a $LOG
	echo "Cleaning up previous compilation.." | tee -a $LOG
	echo "=========================" | tee -a $LOG
	cd ./$PHP
	make clean > ./.$LOG
	cd ..
fi

#############################################
# Untar sources
#############################################

echo "=========================" | tee -a $LOG
echo "Unpacking..." | tee -a $LOG
echo "=========================" | tee -a $LOG

# untar php
rm -r $PHP >& /dev/null
tar -zxvf $PHP.tar.gz >& /dev/null

#############################################
# collect available [configure --help] options
#############################################

echo "=========================" | tee -a $LOG
echo "Collecting available configuration options..." | tee -a $LOG
echo "=========================" | tee -a $LOG

cd ./$PHP
./configure --help > ./../$TEMP/config-options-$PHP.log
sleep 2
cd ..

############################################
# PHP START COMPILATION
############################################

cd $PHP

./configure \
	--prefix=/usr/local/php5 \
	--exec-prefix=/usr/local/php5 \
	--libdir=/usr/local/php5/lib \
	--with-apxs2=/usr/sbin/apxs \
	--with-config-file-path=$PHPINI \
	--enable-calendar \
	--enable-shared \
	--enable-inline-optimization \
	--with-openssl \
	--with-kerberos \
	--with-zlib \
	--with-curl \
	--enable-zend-multibyte \
	--enable-ftp \
	--enable-sysvsem \
	--enable-sysvshm \
	--enable-bcmath \
	--enable-sigchild \
	--enable-mbstring \
	--enable-mbregex \
	--enable-soap \
	--enable-sockets \
	--with-pcre-regex \
	--enable-pcntl \
	--enable-wddx \
	--enable-zip \
	--with-gd \
	--enable-gd-native-ttf \
	--with-jpeg-dir=/usr/local \
	--with-png-dir=/usr/local \
	--with-freetype-dir=/usr/local \
	--with-ldap \
	--with-bz2 \
	--with-mhash \
	--with-mcrypt \
	--with-imap \
	--with-imap-ssl \
	--with-xsl \
	--with-xmlrpc \
	--with-tidy \
	--with-oci8=shared,instantclient,/usr/local/oracle/instantclient_10_2 \
	--with-pdo-oci=instantclient,/usr/local/oracle/instantclient_10_2,10.2 \
	--without-sqlite \
	--without-pear \
	>> ./.$LOG

sleep 2

cd ..
chmod -R 777 $PHP
chown -R root $PHP

echo "=========================" >> $LOG
echo "PHP - running make.." >> $LOG
echo "=========================" >> $LOG

cd ./$PHP
make >> ./.$LOG
sleep 2
cd ..

chmod -R 777 $PHP
chown -R root $PHP

echo "=========================" >> $LOG
echo "PHP - running make install.." >> $LOG
echo "=========================" >> $LOG

cd ./$PHP
make install >> ./.$LOG
sleep 2

echo "Creating $PHPINI"
mkdir $PHPINI >& /dev/null
echo "Copying php.ini development configuration file into $PHPINI"
cp php.ini-development ${PHPINI}/php.ini

cd ..
echo "DONE! Check logs in [$LOG]"
echo "=========================="
echo "NOW:"
echo "restart apache with command:[service httpd restart]"
echo "-- now you may want to: --"
echo " --> run phpinfo() and check available PHP extensions. If needed add extensions into ${PHPINI}/php.ini, e.g. extension=oci8.so"
echo " --> set DATE timezone in php.ini"
echo " --> check oracle oci_connect()/pdo connect. If needed, set oracle environment variables (TNS..) via virtual host."
echo " --> install debugging server modules"
echo " --> setup httpd virtual host for your PHP project"
echo " --> map www-root directory via samba into windows in order to develop on Win-based PHP IDE"
echo " --> set access permissions to www document-root (owner should be apache, mode 644)"
echo " --> good luck!"

# if OCI8/PDO_OCI compiled but not loaded, add into php.ini (/etc/php/php.ini) as needed:
# extension=pdo_oci.so
# extension=oci8.so

Voala! Now you should have PHP 5.3.3 compiled in /usr/local/php5. Restart apache service httpd restart, create file in your document root directory with phpinfo() and check loaded modules.

Potential problems

==========================================
PROBLEM 1: apxs not found
==========================================
if apxs not found, try:
locate apxs
if not found, you have to install httpd-devel package like this (cca 40 Mb):
yum install httpd-devel
run:
updatedb
locate apxs

Now you should see apxs path e.g. [/usr/sbin/apxs]

==========================================
PROBLEM 2: xml2-config not found. Please check your libxml2 installation.
==========================================
yum install libxml2-devel
==========================================
PROBLEM 3: configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing
==========================================
1. yum install libc-client
2. yum install libc-client-devel
==========================================
PROBLEM 4: warning: "LBER_NULL" redefined ..
==========================================
/usr/local/oracle/instantclient_11_2/sdk/include/ldap.h:96:1: warning: "LBER_NULL" redefined
In file included from /usr/local/src/php-5.3.3/ext/ldap/php_ldap.h:27,
from /usr/local/src/php-5.3.3/ext/ldap/ldap.c:45:
/usr/include/lber.h:82:1: warning: this is the location of the previous definition
In file included from /usr/local/src/php-5.3.3/ext/ldap/php_ldap.h:30,
from /usr/local/src/php-5.3.3/ext/ldap/ldap.c:45:

This is problem related to instantclient 11.X oracle client. See:
http://ubuntuforums.org/showthread.php?t=1434835
(redeclared headers for LDAP in instantclient 11g sources)

Solution:
Install instantclient 10.2.0.5, (don't use 11g), download instantclient+sqlplus+sdk for linux x86 from:
http://www.oracle.com/technetwork/topics/linuxsoft-082809.html

==========================================
PROBLEM 5: Warning: oci_connect() [function.oci-connect]: ORA-12541: TNS:no listener in /var/www/html/test-ora.php on line 17
==========================================

This means, you are trying to connect to oracle server where MUST be installed oracle database and must be started up. Once started up, there should be listener. If no listener, it means you are trying to connect to invalid IP or oracle is not started. Check that IP is correct e.g. by telnet YO.U.R.IP.

Read: http://ubuntuforums.org/archive/index.php/t-92528.html

==========================================
PROBLEM 6: ORA-12154: TNS:could not resolve the connect identifier specified in ...
==========================================
This means oracle cannot find TNS names. You should define TNS_ADMIN in your virtual host e.g.:
SetEnv TNS_ADMIN "C:\oracle\product\10.2.0\client_1\NETWORK\ADMIN"

Overview of oracle connection strings:
http://alisonatoracle.blogspot.com/2006/02/oracle-database-connection-strings-in.html

==========================================
PROBLEM 7: PHP-CLI (command line interface) points to different PHP version, e.g. 5.1.6, whereas it should use e.g. 5.3.4
==========================================
7.1 -> Check current CLI PHP version:
php -v
e.g.
PHP 5.1.6 (cli) (built: Dec 21 2010 13:37:09)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2008 Zend Technologies

7.2 -> find which binary file uses:
which php
e.g. /usr/bin/php

7.3 -> point to new PHP version:

a) rename /usr/bin/php to /usr/bin/php.old

b) create symbolic link pointing to newly compiled PHP, e.g. /usr/local/php5/bin/php:
    ln -s /usr/local/php5/bin/php          /usr/bin/php

NOTE:
Optionally you may want to update also [php-config] and [phpize] used for compiling PHP sources and extensions:
    ln -s /usr/local/php5/bin/php-config   /usr/bin/php-config
    ln -s /usr/local/php5/bin/phpize       /usr/bin/phpize

c) re-check php version [php -v], you should see now new target PHP version:
   PHP 5.3.4 (cli) (built: Dec 21 2010 13:37:09)
   Copyright (c) 1997-2010 The PHP Group
   Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

Got a question?

Synet.sk

Professional development of web applications and custom solutions. Consultancy services.

Demo

Contact


https://synet.sk