编译安装PHP的企业微信扩展,最好使用CentOS7.9,不支持Windows和macOS,Ubuntu的兼容性也有问题。
由于扩展的兼容性问题,需要禁用intl扩展,在编译之前需要先重新编译安装PHP并禁用intl,可参考 宝塔面板自定义参数编译安装PHP。
参考文章:https://gitee.com/it1/php7-wxwork-finance-sdk
这里是将代码clone到/root
目录下,将预先编译好了PHP 7.4版本。
正式编译:
/www/server/php/74/bin/phpize
./configure --with-php-config=/www/server/php/74/bin/php-config --with-wxwork-finance-sdk=/root/php7-wxwork-finance-sdk-master
make
编译完成后的提示:
Libraries have been installed in:
/root/php7-wxwork-finance-sdk-master/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
按照提示编辑 /etc/ld.so.conf
,把 /root/php7-wxwork-finance-sdk-master/modules
作为新行添加进去,再执行命令ldconfig
对当前用户生效。如果要以www用户执行定时任务或守护进程,需要重启服务器。
编译测试和安装
make test
make install
配置php.ini
:
[wxwork_finance_sdk]
extension = /www/server/php/74/lib/php/extensions/no-debug-non-zts-20190902/wxwork_finance_sdk.so
然后重启下php-fpm服务就可以使用了。