项目中需要对某些PHP文件进行加密,这里选用PHP PECL中的bcompiler库,可以使用phpize编译动态库或直接使用pecl命令(需要安装php-pear)。
系统环境CentOS release 6.4 (Final) PHPPHP 5.3.28 。
第一种方法,使用pecl命令:
1. 搜索php-pear安装包:
[root@phpabc.cn]# yum search php53 | grep pear php53u-pear.noarch : PHP Extension and Application Repository framework |
2. 安装php53u-pear:
[root@phpabc.cn]# yum install php53u-pear |
3. 安装完毕后,可以测试pecl命令:
[root@phpabc.cn]# pecl help Commands: build Build an Extension From C Source bundle Unpacks a Pecl Package channel-add Add a Channel channel-alias Specify an alias to a channel name channel-delete Remove a Channel From the List channel-discover Initialize a Channel from its server channel-info Retrieve Information on a Channel channel-login Connects and authenticates to remote channel server channel-logout Logs out from the remote channel server channel-update Update an Existing Channel clear-cache Clear Web Services Cache config-create Create a Default configuration file config-get Show One Setting config-help Show Information About Setting config-set Change Setting config-show Show All Settings convert Convert a package.xml 1.0 to package.xml 2.0 format cvsdiff Run a "cvs diff" for all files in a package cvstag Set CVS Release Tag download Download Package download-all Downloads each available package from the default channel info Display information about a package install Install Package list List Installed Packages In The Default Channel list-all List All Packages list-channels List Available Channels list-files List Files In Installed Package list-upgrades List Available Upgrades login Connects and authenticates to remote server [Deprecated in favor of channel-login] logout Logs out from the remote server [Deprecated in favor of channel-logout] makerpm Builds an RPM spec file from a PEAR package package Build Package package-dependencies Show package dependencies package-validate Validate Package Consistency pickle Build PECL Package remote-info Information About Remote Packages remote-list List Remote Packages run-scripts Run Post-Install Scripts bundled with a package run-tests Run Regression Tests search Search remote package database shell-test Shell Script Test sign Sign a package distribution file svntag Set SVN Release Tag uninstall Un-install Package update-channels Update the Channel List upgrade Upgrade Package upgrade-all Upgrade All Packages [Deprecated in favor of calling upgrade with no parameters] Usage: pecl [options] command [command-options] <parameters> Type "pecl help options" to list all options. Type "pecl help shortcuts" to list all command shortcuts. Type "pecl help <command>" to get the help for the specified command. |
说明安装成功,接下安装bcompiler模块了:
[root@phpabc.cn]# pecl install bcompiler WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update downloading bcompiler-1.0.2.tgz ... Starting to download bcompiler-1.0.2.tgz (57,347 bytes) ..............done: 57,347 bytes 11 source files, building running: phpize ...............省略................ Build process completed successfully Installing '/usr/lib64/php/modules/bcompiler.so' install ok: channel://pecl.php.net/bcompiler-1.0.2 configuration option "php_ini" is not set to php.ini location You should add "extension=bcompiler.so" to php.ini |
这时,如果没有出现任何错误,说明已经顺利编译好了bcompiler.so模块,最后一步是编辑php.ini,加入动态库extension=bcompiler.so。
第二种方法,手动编译bcompiler,步骤如下:
[root@phpabc.cn]# wget http://pecl.php.net/get/bcompiler [root@phpabc.cn]# mv bcompiler bcompiler.tar.gz [root@phpabc.cn]# tar zxf bcompiler.tar.gz [root@phpabc.cn]# cd bcompiler-1.0.2/ [root@li382-196 bcompiler-1.0.2]# phpize Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626 [root@li382-196 bcompiler-1.0.2]# ./configure [root@li382-196 bcompiler-1.0.2]# make [root@li382-196 bcompiler-1.0.2]# make install Installing shared extensions: /usr/lib64/php/modules/ [root@li382-196 bcompiler-1.0.2]# ls /usr/lib64/php/modules/ bcmath.so curl.so gd.so mbstring.so mysqli.so pdo_mysql.so pdo_sqlite.so zip.so bcompiler.so fileinfo.so json.so mcrypt.so mysql.so pdo.so phar.so |
如果上面的步骤没有出错,就可以看到bcompiler.so已经编译成功,最后就是在php.ini中加载bcompiler.so了。
而对于php 5.4,暂时还没有编译成功,似乎暂不支持,会出现如下错误:
running: make /bin/sh /var/tmp/pear-build-rootNeVId6/bcompiler-1.0.2/libtool --mode=compile cc -I. -I/var/tmp/bcompiler -DPHP_ATOM_INC -I/var/tmp/pear-build-rootNeVId6/bcompiler-1.0.2/include -I/var/tmp/pear-build-rootNeVId6/bcompiler-1.0.2/main -I/var/tmp/bcompiler -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 -DHAVE_CONFIG_H -g -O2 -c /var/tmp/bcompiler/php_bcompiler.c -o php_bcompiler.lo libtool: compile: cc -I. -I/var/tmp/bcompiler -DPHP_ATOM_INC -I/var/tmp/pear-build-rootNeVId6/bcompiler-1.0.2/include -I/var/tmp/pear-build-rootNeVId6/bcompiler-1.0.2/main -I/var/tmp/bcompiler -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 -DHAVE_CONFIG_H -g -O2 -c /var/tmp/bcompiler/php_bcompiler.c -fPIC -DPIC -o .libs/php_bcompiler.o /var/tmp/bcompiler/php_bcompiler.c: 在函数‘_bcompiler_write_functions_from_file’中: /var/tmp/bcompiler/php_bcompiler.c:468: 警告:传递‘apc_serialize_zstring’的第 1 个实参时丢弃了指针目标类型的限定 /var/tmp/bcompiler/php_bcompiler.h:298: 附注:需要类型‘char *’,但实参的类型为‘const char *’ /var/tmp/bcompiler/php_bcompiler.c: 在函数‘zif_bcompiler_write_file’中: /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:574: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:581: 警告:传递‘apc_serialize_zend_class_entry’的第 4 个实参时丢弃了指针目标类型的限定 /var/tmp/bcompiler/php_bcompiler.h:305: 附注:需要类型‘char *’,但实参的类型为‘const char *’ /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 /var/tmp/bcompiler/php_bcompiler.c:635: 错误:‘zend_class_entry’没有名为‘filename’的成员 make: *** [php_bcompiler.lo] 错误 1 ERROR: `make' failed |