Centos

CentOS 6:PHP無法載入我編譯的gdchart.so和oci8.so

  • February 12, 2016

我一直在嘗試向新安裝的 CentOS 6.0 Linux 伺服器添加 2 個 PHP 擴展,但在 /var/log/httpd/error_log 中得到錯誤消息:

[notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:httpd_t:s0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/gdchart.so' - /usr/lib64/php/modules/gdchart.so: undefined symbol: php_gd_gdFontMediumBold in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/oci8.so' - libnnz11.so: cannot enable executable stack as shared object requires: Permission denied in Unknown on line 0
[notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.3.2 mod_ssl/2.2.15 OpenSSL/1.0.0-fips mod_wsgi/3.2 Python/2.6.5 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations

我確實跑了

# chcon system_u:object_r:lib_t:s0 /usr/lib64/php/modules/oci8.so
# chcon system_u:object_r:lib_t:s0 /usr/lib64/php/modules/gdchart.so
# ls -alZ /usr/lib64/php/modules/

-rwxr-xr-x. root root system_u:object_r:lib_t:s0       curl.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       dom.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       fileinfo.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       gdchart.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       gd.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       json.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       oci8.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       pdo_pgsql.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       pdo.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       pdo_sqlite.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       pgsql.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       phar.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       sqlite3.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       wddx.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       xmlreader.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       xmlwriter.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       xsl.so
-rwxr-xr-x. root root system_u:object_r:lib_t:s0       zip.so

以下是我編譯這兩個模組的方法:

  1. 對於 oci8.so - 設置 /etc/tnsnames.ora 然後:
# rpm -Uvh oracle-instantclient11.2-basic-11.2.0.2.0.x86_64.rpm
# rpm -Uvh oracle-instantclient11.2-devel-11.2.0.2.0.x86_64.rpm
# pecl install oci8 (entered: instantclient,/usr/lib/oracle/11.2/client64/lib there)
  1. 對於 gdchart.so:
# yum install gd-devel php-devel gcc
# wget http://pecl.php.net/get/gdchart-0.2.0.tgz
# tar xvfz $!
# cd $!
# ./phpize
# ./configure
# make && make install

有沒有人有一個想法,我錯過了什麼?

從命令行使用這兩個庫(Oracle 即時客戶端和 GDChart)都可以。

更新:

當我通過將SELINUX=permissive放入 /etc/selinux/config 並重新啟動來關閉 SELinux 時,oci8.so 會載入,但 gdchart.so 仍然存在錯誤

所以我想我的問題是:如何重新啟用 SELinux 並且仍然能夠使用 oci8.so?請在這里分享您的經驗 - 如果您已經在使用 Oracle + PHP + CentOS/RHEL 6。

更新 2:

啟動 Apache 時,我在 /var/log/audit/audit.log 中看到:

type=AVC msg=audit(1316698464.300:51213): avc:  denied  { execstack } for  pid=2833 comm="httpd" scontext=unconfined_u:system_r:httpd_t:s0 tcontext=unconfined_u:system_r:httpd_t:s0 tclass=process
type=SYSCALL msg=audit(1316698464.300:51213): arch=c000003e syscall=10 success=yes exit=0 a0=7fff95f4b000 a1=1000 a2=1000007 a3=7f5e22611000 items=0 ppid=1 pid=2833 auid=10116 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=34 comm="httpd" exe="/usr/sbin/httpd" subj=unconfined_u:system_r:httpd_t:s0 key=(null)

以 root 身份執行以下命令,然後重試:

# setsebool -P allow_execstack 1

您還可以僅通過以下方式啟用可執行堆棧oci8.so

# execstack -c /usr/lib64/php/modules/oci8.so

也許這是舊消息,但我得到了 PHP/5.3.3 和 OCI8(Oracle 即時客戶端 10.2.0.5)在 RHEL6.3 上執行,通過執行以下操作啟用了 SELinux:

chcon system_u:object_r:lib_t:s0 /usr/lib64/php/modules/oci8.so
execstack -c /usr/lib/oracle/<VERSION>/client64/lib/*.so
chcon -t texrel_shlib_t /usr/lib/oracle/<VERSION>/client64/lib/*.so
setsebool -P httpd_can_network_connect_db 1

我結合使用了這篇文章audit2allow -w -a中的提示來得出這個成功的結論。

引用自:https://serverfault.com/questions/314336