用於執行「pecl install oci8」的 Bash 腳本

用於執行「pecl install oci8」的 Bash 腳本

我正在嘗試建立 shell 腳本來執行 vagrant vm(運行 Ubuntu 12.04)的初始配置。一切(安裝 php、apache、oracle instantclient 等)都工作正常,除了最後一步 - 安裝 php oci8 擴充:

pecl install oci8

當我手動運行此命令(帶有 sudo 前綴)時,它工作正常。但是當腳本運行此命令時,它會失敗,如下所示:

running: make
/bin/bash /tmp/pear/temp/pear-build-rootG74SsU/oci8-2.0.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/oci8 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootG74SsU/oci8-2.0.6/include -I/tmp/pear/temp/pear-build-rootG74SsU/oci8-2.0.6/main -I/tmp/pear/temp/oci8 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/oci8/oci8.c -o oci8.lo
libtool: compile:  cc -I. -I/tmp/pear/temp/oci8 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootG74SsU/oci8-2.0.6/include -I/tmp/pear/temp/pear-build-rootG74SsU/oci8-2.0.6/main -I/tmp/pear/temp/oci8 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/oci8/oci8.c  -fPIC -DPIC -o .libs/oci8.o
In file included from /tmp/pear/temp/oci8/oci8.c:48:0:
/tmp/pear/temp/oci8/php_oci8_int.h:60:17: fatal error: oci.h: No such file or directory
compilation terminated.
make: *** [oci8.lo] Error 1
ERROR: `make' failed

pecl腳本在安裝開始時要求輸入路徑,我認為這就是問題所在:

Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] :

若要繼續安裝,您需要提供 ORACLE_HOME 目錄或按Enter。我已在其他地方嘗試過以下建議,但它不起作用 - 輸出中缺少換行符(與pecl手動運行命令時相比),因此它無法正確模擬Enter擊鍵:

printf "\n" | pecl install oci8

關於如何讓它正常運作有什麼建議嗎?

答案1

我的解決方案是運行以下命令:

export C_INCLUDE_PATH=/usr/include/oracle/11.2/client

並重新啟動:

pecl insatlla oci8

答案2

我並沒有真正找到解決這個問題的通用解決方案。在我的特定場景(透過 Vagrant 配置)中,最終的工作是使用 Puppet 清單來執行此特定配置步驟,這很簡單,因為您只需在 Shell 配置程式之後在 Vagrant 配置中指定它:

"pecl-install-oci8":
    command => "pecl install oci8",
    user => root,
    timeout => 0,
    tries   => 5,
    unless => "/usr/bin/php -m | grep -c oci8";

由於某種我尚未弄清楚的原因,puppet 安裝 oci8 沒有問題。

當我完成此操作後,我將整個腳本移植到 Puppet 清單中,但這是偏離主題的。

答案3

通常,對於此類安裝,您可以回顯要設定的參數。我包裝了整個語句,以便可以使用 sudo 權限執行它

sudo sh -c "echo 'instantclient,/opt/oracle/instantclient' | pecl install oci8"

相關內容