运行“pecl install oci8”的 Bash 脚本

运行“pecl install oci8”的 Bash 脚本

我正在尝试创建 shell 脚本来对 vagrant vm(运行 Ubuntu 12.04)进行初始配置。除了最后一步 - 安装 php oci8 扩展之外,所有操作(安装 php、apache、oracle instantclient 等)都运行正常:

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"

相关内容