環境: CentOS 7 x64 + PHP 5.6 + httpd (都用 yum 直接取得)

步驟:

# 從 Oracle 下載 Oracle Instant Client 12.1.0.2
#     oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
#     oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
# 安裝 Oracle Instant Client

rpm -Uvh oracle-instantclient12.1-*.rpm

#
# 安裝其他套件
#

yum -y install gcc
yum -y install prelink

#
# 取得 php 的 source code
# 注意! 要與安裝的 php 版本一致
#

cd ~
wget http://php.net/distributions/php-5.6.19.tar.gz
tar -xvzf php-5.6.19.tar.gz

#
# 建置 oci8.so
#

cd ~/php-5.6.19/ext/oci8
phpize
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/12.1/client64/lib
make
make install
echo extension=oci8.so > /etc/php.d/oci8.ini
php -m | grep -i oci

#
# 建置 pdo_oci
#

cd ~/php-5.6.19/ext/pdo_oci
phpize
./configure --prefix=/usr --exec-prefix=/usr --with-php-config=php-config --with-pdo-oci=instantclient,/usr,12.1
make
make install
echo extension=pdo_oci.so > /etc/php.d/pdo_oci.ini
php -m | grep -i oci

#
# 設定權限
#

setsebool -P httpd_can_network_connect=1
execstack -c /usr/lib64/php/modules/oci8.so
execstack -c /usr/lib64/php/modules/pdo_oci.so
execstack -c /usr/lib/oracle/12.1/client64/lib/libclntsh.so.12.1

#
# 重開 httpd
#

systemctl restart httpd

#
測試
#

cat << EOF > /var/www/html/pdo-connect.php
<?php
    \$db_username = 'Oracle帳號';
    \$db_password = 'Oracle密碼';
    \$db_host = 'Oracle IP or Host';
    \$db_sid = 'Oracle SID';
    try {
        \$conn = new PDO('oci:dbname='.\$db_host.'/'.\$db_sid, \$db_username, \$db_password);
    } catch (PDOException \$e) {
        echo (\$e->getMessage());
    }
?>
EOF

 

#
# 參考資料
#
PDO_OCI のインストール(CentOS7対応)
RHEL/CentOS/Ubuntu 와 Windows 에 오라클 DB 드라이버(OCI8/PDO_OCI) PHP extension 설치하기
Oracle Functions (PDO_OCI)
#

 

創作者介紹

Egg Chang 的部落格

Egg Chang 發表在 痞客邦 PIXNET 留言(0) 人氣()