首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PHP oci8不能通过pecl安装:"fatal error: oci8_dtrace_gen.h“

PHP oci8不能通过pecl安装:"fatal error: oci8_dtrace_gen.h“
EN

Stack Overflow用户
提问于 2017-05-25 00:04:29
回答 4查看 17K关注 0票数 7

我正在尝试将我的fedora 25 webserver - php连接到Oracle数据库。

要做到这一点,我需要pecl安装oci8。

然而,我得到了这个错误:

代码语言:javascript
运行
复制
/bin/sh /var/tmp/pear-build-roottqYEC6/oci8-2.1.4/libtool --mode=compile cc  -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-roottqYEC6/oci8-2.1.4/include -I/var/tmp/pear-build-roottqYEC6/oci8-2.1.4/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/oracle/12.1/client64  -DHAVE_CONFIG_H  -g -O2   -c /var/tmp/oci8/oci8.c -o oci8.lo
libtool: compile:  cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-roottqYEC6/oci8-2.1.4/include -I/var/tmp/pear-build-roottqYEC6/oci8-2.1.4/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/oracle/12.1/client64 -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8.c  -fPIC -DPIC -o .libs/oci8.o
In file included from /var/tmp/oci8/oci8.c:49:0:
/var/tmp/oci8/php_oci8_int.h:46:29: fatal error: oci8_dtrace_gen.h: No such file or directory
 #include "oci8_dtrace_gen.h"
                             ^
compilation terminated.
Makefile:196: recipe for target 'oci8.lo' failed
make: *** [oci8.lo] Error 1
ERROR: `make' failed

我不知道该怎么办。我到处寻找解决方案,但我只能找到过时的文章。

任何帮助都非常感谢!

EN

回答 4

Stack Overflow用户

发布于 2017-05-30 11:10:42

看起来你的PHP是在启用DTrace支持的情况下构建的。由于PHP构建和配置文件的一些限制,PECL OCI8安装也需要一个提示才能使用DTrace进行构建:

代码语言:javascript
运行
复制
$ export PHP_DTRACE=yes
$ pecl install oci8

http://php.net/manual/en/oci8.dtrace.php中提到了这一点

票数 15
EN

Stack Overflow用户

发布于 2018-11-15 05:00:06

注意:我得到了相同的oci8_dtrace_gen.h,但是'sudo yum install systemtap-sdt-devel && export && pecl install oci8‘没有帮助(添加了systemtap-stp-devel步骤,因为下面的评论提醒我,我确实在一些文章中读到了我必须为DTRACE安装它)。

我不得不手动构建一些文章推荐的版本:

代码语言:javascript
运行
复制
$ sudo yum install php-pear php-devel
$ pear download pecl/oci8 
$ tar xvzf oci8-2.1.8.tgz 
$ cd oci8-2.1.8/
$ phpize
# make sure of the instantclient path below... mine was version 18.3 so it was located in this folder... Also make note some tutorials ask for the ORACLE_HOME folder which theoretically is /usr/lib/oracle/18.3/client64 but if its instantclient then put the lib folder underneath it (worked for me at least:)
$ ./configure --with-oci8=instantclient,/usr/lib/oracle/18.3/client64/lib
$ make 
$ make install
#NOW an .so file built in: /usr/lib64/php/modules/oci8.so
#THIS STEP NOT NEEDED if SELinux disabled on your server/box, but if SELinux is enabled run: setsebool -P httpd_execmem 1
#NOW add:     extension=oci8.so     at the bottom of your php.ini file (probab in /etc/php.ini)
$ sudo service httpd restart
# note that you can also install PDO_OCI to connect to oracle but its very old and not as good as OCI8 lib (and maybe dependent on having OCI8 anyway)

Beforehand you may want to test and make sure the instantclient libs installed correctly by trying sqlplus:

$ sudo rpm -ivh oracle-instantclient18.3-basic-18.3.0.0.0-1.x86_64.rpm
$ sudo rpm -ivh oracle-instantclient18.3-sqlplus-18.3.0.0.0-1.x86_64.rpm
$ sudo rpm -ivh oracle-instantclient18.3-devel-18.3.0.0.0-1.x86_64.rpm
$ sudo rpm -ivh oracle-instantclient18.3-tools-18.3.0.0.0-1.x86_64.rpm
#add your TNSNAMES connection string info below to this file
$ sudo touch /usr/lib/oracle/18.3/client64/network/admin/tnsnames.ora 
$ vi ~/.bash_profile
#add below info to bash_profile to test sqlplus
ORACLE_HOME=/usr/lib/oracle/18.3/client64
export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib
export LD_LIBRARY_PATH
TNS_ADMIN=$ORACLE_HOME/lib/network/admin
export TNS_ADMIN
# log out and log back in and test, sqlplus should have access to TNS_ADMIN now
$ sqlplus username/pass@TNSNAMES_SHORTCUT_OF_THE_DB_CONNECTION

然后,您可能希望检查phpinfo()输出,以确保apache可以在其环境部分访问ORACLE_HOME、TNS_ADMIN、httpd(我在/etc/sysconfig/ LD_LIBRARY_PATH中定义了这些内容)。

然后,您可以使用如下所示的简单脚本测试OCI ...我放置了各种连接字符串格式,这些格式对我有效,您可以取消注释并进行测试(有些依赖于EZCONNECT样式,或者假设您已经正确设置了TNS_ADMIN。第一个未注释的$db是最简单的):

代码语言:javascript
运行
复制
<?php

//works
// ... as long as $TNS_NAMES is defined and passed to apache correctly (using /etc/sysconfig/httpd to add the var.... after defined ORACLE_HOME in there, DONT USE $ORACLE_HOME to define the rest of the vars like for TNS_ADMIN... aka dont do this: TNS_ADMIN=$ORACLE_HOME/lib/network/admin ... use full path: TNS_ADMIN=/usr/lib/oracle/18.3/client64/lib/network/admin )
$username = "myusername";
$password = "mypassword\$2"; //note: may need to escape some chars here like for me i had to escape $ with a backslash
$db = "TNSNAMES_SHORTCUT_OF_THE_DB_CONNECTION";

// works
/*
$db = <<<EOT
  (DESCRIPTION=
    (ADDRESS=
      (PROTOCOL=TCP)
      (HOST=mydbhost.example.com)
      (PORT=1521)
    )
    (CONNECT_DATA=
      (SERVER=dedicated)
      (SERVICE_NAME=name.of.the.service.here)
    )
 )
EOT;
*/

//works, double-check with your DBA as maybe you want to connect to a specific SID or different connection string format
//$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mydbhost.example.com)(PORT = 1521)))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=name.of.the.service.here)))";

// works
// ezconnect format: username/password@[//]host[:port][/service_name] (username and pass are already in oci_connect function so removed from below)
//$db = '//mydbhost.example.com:1521/name.of.the.service.here';

$conn = oci_connect( $username, $password, $db);
if (!$conn) {
  $m = oci_error();
  trigger_error(htmlentities($m['message']), E_USER_ERROR);
}

$sql = "select SYSDATE from DUAL";
$stid = oci_parse($conn, $sql);
oci_execute($stid);
while ($row = oci_fetch_array ($stid)) {
  echo $row[0]."&lt;br&gt;";
}
oci_free_statement($stid);
oci_close($conn);
票数 6
EN

Stack Overflow用户

发布于 2020-09-02 19:50:24

我无法在我的CentOS6服务器上安装RPM包,所以我尝试手动安装,但遇到了许多问题,包括DTRACE选项的问题。

下面是我升级OCI8所做的(升级到PHP7.3破坏了网络应用程序)。

希望这对其他人有用。

从Oracle下载Instant Client Zip文件并在服务器上解压(我让top从浏览器下载它们,然后将它们SCP到服务器):

代码语言:javascript
运行
复制
cd /u01/app/oracle/product/InstClient/
unzip instantclient-basic-linux.x64-11.2.0.4.0.zip

这将创建SDK子目录,将instantclient_11_2解压到相同的位置:

代码语言:javascript
运行
复制
unzip instantclient-sdk-linux.x64-11.2.0.4.0.zip

编辑/etc/sysconfig/httpd并将LD_LIBABRY_PATH指向新的instantclient_11_2主目录。

Sym链接库:

代码语言:javascript
运行
复制
ln -s /u01/app/oracle/product/InstClient/instantclient_11_2/libclntsh.so.11.1  /u01/app/oracle/product/InstClient/instantcliet_11_2/libclntsh.so

从php.net获取oci8源码包:

代码语言:javascript
运行
复制
wget https://pecl.php.net/get/oci8-2.2.0.tgz
tar xf oci8-2.2.0.tgz
cd oci8-2.2.0
phpize

需要升级autoconf并安装systemtap-sdt-devel

代码语言:javascript
运行
复制
wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
gunzip autoconf-latest.tar.gz
tar xf autoconf-latest.tar
cd autoconf-2.69
./configure
make
make install
yum install systemtap-sdt-devel

继续使用OCI8:

代码语言:javascript
运行
复制
cd ../oci8-2.2.0
phpize
phpize 7.3
export PHP_DTRACE=yes
./configure --with-oci8=instantclient,/u01/app/oracle/product/InstClient/instantclient_11_2 --with-php-config=/usr/bin/php-config
make
make test

测试报告了许多失败,但估计由于没有正确的数据库登录凭据,所以继续:

代码语言:javascript
运行
复制
make install
ls -ltr /usr/lib64/php/modules/ # check oci8.so is updated

service httpd restart
php -v # No OCI8 error reported and web app working
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44163450

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档