对于php+mysql来说,一般相对比较简单,然而对于oracle+php的方式相对就比较复杂了,下面是笔者开发基于oracle的php 监控环境配置

 

启动以Oracle启动oracle
启动httpd
http.sh

#!/bin/bash
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/local/lib:/lib:
ORACLE_SID=fsxy
ORACLE_HOME=/opt/ora_home
export ORACLE_HOME
export ORACLE_SID
export LD_LIBRARY_PATH
/usr/local/httpd/bin/apachectl $1

echo $ORACLE_SID
echo $ORACLE_HOME
echo $LD_LIBRARY_PATH

 

 

 

 

http://wiki.oracle.com/page/PHP+Oracle+FAQ
http://php.net/manual/en/oci8.installation.php

 

mysql: 5.0.22-log
http:httpd:2.2.13
php:5.3.5
Oracle10g
oracle-instantclient-basic-10.2.0.4.1.i386.rpm
oracle-instantclient-devel-10.2.0.4.1.i386.rpm
安装http
cd /usr/local/httpd
tar -zxvf httpd-2.2.13.tar.gz
cd httpd-2.2.13

 ./configure –prefix=/usr/local/httpd –enable-module=so
 
 make clean
 make
 make install
 

  
启动/关闭http
/usr/local/.http/bin/apachectl stop
/usr/local/.http/bin/apachectl start
创建启动脚本

 

 

 

 

 

 

====================================================================================================== 
====================================================================================================== 

安装php

 

 
root#

#cd /usr/local/php

# tar -xjf php-5.0.2.tar.bz2
# cd php-5.0.2
编译

[root@master php-5.3.5]# pwd
/usr/local/php/php-5.3.5
=========================================
创建orauser存放instantclient
useradd orauser
passwd orauser
mkdir -p /home/orauser/instantcliente

将下面的包上传到/home/orauser/
instantclient-basic-linux32-10.1.0.5-20060511.zip
instantclient-sdk-linux32-10.1.0.5-20060511.zip
cd /home/orauser/instantcliente

unzip instantclient-basic-linux32-10.1.0.5-20060511.zip 
unzip instantclient-sdk-linux32-10.1.0.5-20060511.zip
 
自动安装sdk(创建相关的目录)

安装instantclient
useradd -g oinstall -G dba orauser
pass orauser
[root@master ~]# cp oracle-instantclient-basic-10.2.0.4-1.i386.zip /home/orauser/
su – orauser
unzip oracle-instantclient-basic-10.2.0.4-1.i386.zip

[orauser@master instantclient_10_2]$ ln -s libclntsh.so.10.1 libclntsh.so
[orauser@master instantclient_10_2]$ ln -s libocci.so.10.1 libocci.so

 

 

=====================================================================

 

                  –将php.ini存放在/usr/local/lib目录下–

 

 
[root@FC3 php-5.0.2]# make clean
[root@FC3 php-5.0.2]# make
                                         make test   //测试
[root@FC3 php-5.0.2]# make install

 

 

=======================================
cp /usr/local/php/php-5.3.5/php.ini-development /usr/local/lib/php.ini
vi /usr/local/lib/php.ini

add

extension =/usr/local/lib/php/extensions/oci8.so

将so拷贝到/usr/local/lib/php/extensions目录(之前该目录下没有oci8.so)

[root@master php]# ls
Archive  Console  doc         OS    PEAR5.php    PEAR.php     Structures  test
build    data     extensions  PEAR  pearcmd.php  peclcmd.php  System.php  XML
[root@master php]# pwd
/usr/local/lib/php

将so拷贝
cp /usr/local/lib/php/extensions/no-debug-non-zts-20090626/oci8.so /usr/local/lib/php/extensions/

 
验证http://192.168.182.221/phpinfo.php
oci的相关记录

 
最后操作

 vi /usr/local/httpd/conf/httpd.conf
添加如下内容:
LoadModule php5_module modules/libphp5.so  
AddType application/x-httpd-php .php                            //注意.前面空格
AddType application/x-httpd-php .html
ServerRoot “/usr/local/httpd”                          //不要加www目录

更改
DocumentRoot “/usr/local/httpd/htdocs”            //http网页存放目录,将网页可以存放到该目录

注意编译过程中会自动将Loadmodule添加到配置文件中

 

 

 

****************************************************************
***************************************************************
How do I configure PHP to use Oracle?

The OCI8 and PDO_OCI extensions are included in various PHP distributions, starting with the PHP source code and pre-built binaries for Windows available from www.php.net. Various other packages of PHP are built from the source code release. There are PHP RPMs for Linux on oss.oracle.com, which are also available via up2date to Unbreakable Linux Network subscribers. The Oracle drivers are also included in Zend Core for Oracle and its replacement, Zend Server.

If not using a pre-built package, the basic steps to install OCI8 are:
Download PHP from www.php.net and download Oracle Instant Client.
On Windows, edit your php.ini file and uncomment the following line: extension = php_oci8.dll
Ensure that your extension_dir parameter (in php.ini) contains the directory where the above extension library is located.
On non-Windows platforms rebuild PHP using the following configuration option: –with-oci8=shared,instantclient,/path/to/instant/client/libs
Edit your php.ini file and add: extension = oci8.so
Ensure that your extension_dir parameter (in php.ini) points to the location where oci8.so was installed.
Set environment variables required by Oracle, such as PATH (Windows) or LD_LIBRARY_PATH (on Linux)
Restart you webserver.
There are a number of ways PHP can be configured which allows maximum flexibility. The PHP Documentation gives installation steps for various platforms. Oracle has comprehensive PHP Oracle install instructions covering many possible scenarios on Windows and Linux. The Oracle technical note on installing PHP and Oracle using the small foot-print, free Oracle Instant Client libraries is very popular.

How do I connect to Oracle with the OCI8 Extension?

Using the OCI8 extension:

<?php

$conn = oci_connect(‘myusername’, ‘mypassword’, ‘myhost/XE’);

if (!$conn) {
trigger_error(“Could not connect to database”, E_USER_ERROR);
}

?>

 

 

 

 

 

########################################################################################
…OCIEnvNlsCreate() failed. There is something wrong with your system – please check that ORACLE_HOME is set and points to the right directory…
解决办法:
1.检查测试脚本的环境变量输出是否正常。如果为:

ORACLE_HOME=
NLS_LANG=
PATH=

表示执行apache服务的用户没有得到正确环境变量。建议的解决办法是,将上面写入apachectl文件的文字:
export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/product/10.2.0/
export PATH=$PATH:$ORACLE_HOME/BIN:
export LD_LIBRARY_PATH=/oracle/product/10.2.0/lib:$LD_LIBRARY_PATH

写道/etc/init.d/httpd文件试试,可以写到下面文字之后
apachectl=/usr/sbin/apachectl
httpd=${HTTPD-/usr/sbin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0

2.如果上面的显示正常,请检查oracle安装目录是否能为执行apache服务的用户读取。如果没有,请执行
chown oracle.dba /usr/local/php/ /usr/local/httpd/ -R

===============

重新编译httpd
http端口更改为8080
以oracle启动http

—————–
GD库支持
mkdir -p /usr/local/php/modules/freetype
mkdir -p /usr/local/php/modules/jpeg6
mkdir -p /usr/local/php/modules/gd
mkdir -p /usr/local/php/modules/zlib
mkdir -p /usr/local/php/modules/libxml2
mkdir -p /usr/local/php/modules/libxslt
–mkdir -p /user/local/php/modules/freetds

 

安装 jpeg6
建立目录
[root@master ~]# mkdir -p /usr/local/php/modules/jpeg6/bin
[root@master ~]# mkdir -p /usr/local/php/modules/jpeg6/lib
[root@master ~]# mkdir -p /usr/local/php/modules/jpeg6/include
[root@master ~]# mkdir -p /usr/local/php/modules/jpeg6/man/man1

# cd ~
# tar -zxf jpegsrc.v6b.tar.gz
# cd jpeg-6b
#
./configure –prefix=/usr/local/php/modules/jpeg6/ –enable-shared –enable-static
# make; make install
安装libpng
# cd /tmp
# tar -zxf libpng-1.2.8.tar.gz
# cd libpng-1.2.8
# cp scrīpts/makefile.std makefile
# make; make install

安装 freetype
# cd /root/soft
# tar -zxf freetype-2.1.10.tar.gz
# cd freetype-2.1.10
# ./configure –prefix=/usr/local/php/modules/freetype
# make;make install

 

安装最新的GD库
# cd /tmp
# tar -zxf gd-2.0.33.tar.bz2
# cd gd-2.0.33
#
./configure \
–with-jpeg=/usr/local/php/modules/jpeg6/ \
–with-png –with-zlib –with-freetype=/usr/local/php/modules/freetype

# make; make install

 

安装PHP5

由于php5需libxml2的支持, 所以先下载并安装libxml2
# cd /tmp
# wget http://ftp.gnome.org/pub/GNOME/sources/libxml2/2.6/libxml2-2.6.19.tar.gz
# tar -zxf libxml2-2.6.19.tar.gz
# cd libxml2-2.6.19
#
./configure –prefix=/usr/local/php/modules/libxml2
# make; make install

 
安装 libxslt
# cd /tmp
# wget http://ftp.gnome.org/pub/GNOME/sources/libxslt/1.1/libxslt-1.1.15.tar.gz
# tar -zxf libxslt-1.1.15.tar.gz
# cd libxslt-1.1.15
#
 ./configure –prefix=/usr/local/php/modules/libxslt –with-libxml-prefix=/usr/local/php/modules/libxml2
# make; make install

 

# tar -zxf php-5.3.5.tar.gz
#cd /usr/local/php/php-5.3.5

#
注:支持jpeg需要将解压后的jpeg6目录下的include目录下的所有文件copy到
/root/php-5.3.5/ext/gd/libgd目录下才能正常make
./configure –with-config-file-path=/usr/local/lib \
–with-apxs2=/usr/local/httpd/bin/apxs \
–enable-ftp –enable-sockets \
–with-libxml-dir=/usr/local/php/modules/libxml2 \
–with-xsl=/usr/local/php/modules/libxslt \
–with-oci8=shared,instantclient,/home/orauser/instantclient10_1 \
–with-gd \
–with-freetype-dir=/usr/local/php/modules/freetype –with-zlib-dir=/usr/local/php/modules/zlib \
–with-png-dir=/usr/local/php/modules/libpng \
–with-jpeg-dir=/usr/local/php/modules/jepg6

 

 
#./configure
#make
#make install
注意:重新安装需要重新解压http,instant-client

—————-
cp php.ini-recommended /usr/local/lib/php.ini
vi /usr/local/lib/php.ini
chown -R /usr/local/php
phpinof
gd
oci8
连接oracle