php 8.2 配置安装php-zbarcode扩展

前言

https://www.cnblogs.com/niuben/p/19274540

由于这篇帖子的 php-zbarcode 扩展,不支持 php8

所以使用 https://github.com/micbox/php-zbarcode 来进行安装

下载代码

复制代码
git clone https://github.com/micbox/php-zbarcode
cd php-zbarcode

兼容修复

复制代码
sudo sed -i '92,100s/unsigned int major = 0, minor = 0;/unsigned int major = 0, minor = 0, patch = 0;/' zbarcode.c
sudo sed -i '99s/zbar_version(&major, &minor);/zbar_version(&major, &minor, &patch);/' zbarcode.c
sudo sed -i '100s/"%d.%d"/"%d.%d.%d"/' zbarcode.c

sudo sed -i '354s/instanceof_function_ex(Z_OBJCE_P(image), php_zbarcode_image_sc_entry, 0)/instanceof_function(Z_OBJCE_P(image), php_zbarcode_image_sc_entry)/' zbarcode.c
sudo sed -i '364s/instanceof_function_ex(Z_OBJCE_P(image), php_imagick_get_class_entry(), 0)/instanceof_function(Z_OBJCE_P(image), php_imagick_get_class_entry())/' zbarcode.c

sudo sed -i '/#ifdef HAVE_ZBARCODE_GD/,/#endif/d' zbarcode.c

编译代码

我这里用了宝塔

复制代码
sudo /www/server/php/82/bin/phpize

export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/ImageMagick-6.9.11/bin-q16hdri/pkgconfig:$PKG_CONFIG_PATH"

./configure --with-php-config=/www/server/php/82/bin/php-config --enable-zbarcode-imagick --enable-zbarcode-gd

make clean && make -j$(nproc) && sudo make install

安装成功输出:

复制代码
/bin/sh /usr/local/src/php-zbarcode/libtool --tag=CC --mode=link cc -shared -I/usr/local/src/php-zbarcode/include -I/usr/local/src/php-zbarcode/main -I/usr/local/src/php-zbarcode -I/www/server/php/82/include/php -I/www/server/php/82/include/php/main -I/www/server/php/82/include/php/TSRM -I/www/server/php/82/include/php/Zend -I/www/server/php/82/include/php/ext -I/www/server/php/82/include/php/ext/date/lib -I/usr/include/x86_64-linux-gnu/ImageMagick-6 -I/usr/include/ImageMagick-6  -DHAVE_CONFIG_H  -g -O2 -D_GNU_SOURCE    -o zbarcode.la -export-dynamic -avoid-version -prefer-pic -module -rpath /usr/local/src/php-zbarcode/modules  zbarcode.lo -lzbar -lMagickWand-6.Q16HDRI -lMagickCore-6.Q16HDRI
cc -shared  .libs/zbarcode.o  -lzbar /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16HDRI.so /usr/lib/x86_64-linux-gnu/libMagickCore-6.Q16HDRI.so  -Wl,-soname -Wl,zbarcode.so -o .libs/zbarcode.so
creating zbarcode.la
(cd .libs && rm -f zbarcode.la && ln -s ../zbarcode.la zbarcode.la)
/bin/sh /usr/local/src/php-zbarcode/libtool --tag=CC --mode=install cp ./zbarcode.la /usr/local/src/php-zbarcode/modules
cp ./.libs/zbarcode.so /usr/local/src/php-zbarcode/modules/zbarcode.so
cp ./.libs/zbarcode.lai /usr/local/src/php-zbarcode/modules/zbarcode.la
PATH="$PATH:/sbin" ldconfig -n /usr/local/src/php-zbarcode/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/src/php-zbarcode/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.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

root@VM-16-4-debian:/usr/local/src/php-zbarcode# sudo make install
Installing shared extensions:     /www/server/php/82/lib/php/extensions/no-debug-non-zts-20220829/

配置启用扩展

复制代码
# vim 手动添加 
vim /www/server/php/82/etc/php.ini 
vim /www/server/php/82/etc/php-cli.ini

extension=/www/server/php/82/lib/php/extensions/no-debug-non-zts-20220829/zbarcode.so

立刻验证

bash 复制代码
/www/server/php/74/bin/php -m | grep zbarcode

输出 zbarcode 为成功

创建一个页面,搜索zbarcode 是否存在

php 复制代码
<?php phpinfo(); ?>
相关推荐
lili-felicity5 分钟前
CANN性能调优与实战问题排查:从基础优化到排障工具落地
开发语言·人工智能
独自破碎E7 分钟前
【BISHI15】小红的夹吃棋
android·java·开发语言
进阶小白猿20 分钟前
Java技术八股学习Day33
java·开发语言·学习
执风挽^1 小时前
Python基础编程题2
开发语言·python·算法·visual studio code
Z9fish1 小时前
sse哈工大C语言编程练习20
c语言·开发语言·算法
萧鼎2 小时前
Python 包管理的“超音速”革命:全面上手 uv 工具链
开发语言·python·uv
Anastasiozzzz2 小时前
Java Lambda 揭秘:从匿名内部类到底层原理的深度解析
java·开发语言
刘琦沛在进步2 小时前
【C / C++】引用和函数重载的介绍
c语言·开发语言·c++
机器视觉的发动机3 小时前
AI算力中心的能耗挑战与未来破局之路
开发语言·人工智能·自动化·视觉检测·机器视觉
HyperAI超神经3 小时前
在线教程|DeepSeek-OCR 2公式/表格解析同步改善,以低视觉token成本实现近4%的性能跃迁
开发语言·人工智能·深度学习·神经网络·机器学习·ocr·创业创新