当前位置: 首页 > 编程文章 >

PHP 5.6.23 编译安装 BCMath 扩展步骤详解

PHP 5.6.23 编译安装 BCMath 扩展步骤详解

作者:江言时间:2026-10-09 14:14:30浏览:532

本文介绍在 PHP-5.6.23 环境下通过源码编译方式安装 BCMath 扩展的具体流程。该扩展用于支持任意精度数学计算,安装过程涵盖进入源码目录、执行 phpize 生成配置文件、指定 php-config 路径进行 configure、编译安装以及修改 php.ini 启用模块等关键步骤。完成重启服务后即可使用 bcmath.so 提供的函数功能。

本文目录展开

PHP 5.6.23 编译安装 BCMath 扩展步骤

针对 PHP-5.6.23 版本,采用编译源码的方式安装 BCMath 扩展。

首先导航至 PHP 源代码包中的 ext/bcmath 目录。


[root@192 bcmath]# ls
bcmath.c config.m4 config.w32 CREDITS libbcmath package.xml php_bcmath.h tests

运行位于 PHP 安装目录 bin 文件夹下的 phpize 命令,例如 /usr/local/php/bin/phpize,以准备构建环境。


[root@192 bcmath]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:     20131106
Zend Module Api No:   20131226
Zend Extension Api No:  220131226

接着执行 ./configure 脚本,需根据实际环境指定 --with-php-config 参数,如 /usr/local/php/bin/php-config。


[root@192 bcmath]# ./configure --with-php-config=/usr/local/php/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php
checking for PHP includes... -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226
checking for PHP installed headers prefix... /usr/local/php/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable bc style precision math functions... yes, shared
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h

随后执行 make && make install 命令进行编译及安装操作。


[root@192 bcmath]# make && make install
/bin/sh /home/tools/phptools/php-5.6.23/ext/bcmath/libtool --mode=compile cc -I/home/tools/phptools/php-5.6.23/ext/bcmath/libbcmath/src -I. -I/home/tools/phptools/php-5.6.23/ext/bcmath -DPHP_ATOM_INC -I/home/tools/phptools/php-5.6.23/ext/bcmath/include -I/home/tools/phptools/php-5.6.23/ext/bcmath/main -I/home/tools/phptools/php-5.6.23/ext/bcmath -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2  -c /home/tools/phptools/php-5.6.23/ext/bcmath/bcmath.c -o bcmath.lo 
mkdir .libs
 cc -I/home/tools/phptools/php-5.6.23/ext/bcmath/libbcmath/src -I. -I/home/tools/phptools/php-5.6.23/ext/bcmath -DPHP_ATOM_INC -I/home/tools/phptools/php-5.6.23/ext/bcmath/include -I/home/tools/phptools/php-5.6.23/ext/bcmath/main -I/home/tools/phptools/php-5.6.23/ext/bcmath -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/tools/phptools/php-5.6.23/ext/bcmath/bcmath.c -fPIC -DPIC -o .libs/bcmath.o
... ...
----------------------------------------------------------------------
Libraries have been installed in:
  /home/tools/phptools/php-5.6.23/ext/bcmath/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'.
Installing shared extensions:   /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/

安装完成后,检查 php.ini 中 extension_dir 所指向的目录,确认其中已存在 bcmath.so 文件。


[root@192 sbin]# ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
总用量 3984
-rwxr-xr-x. 1 root root 382568 10月 22 17:57 bcmath.so

在 php.ini 文件的 Dynamic Extensions 配置区块内,新增一行 extension=bcmath.so。

最后重启 PHP 服务使配置生效。

总结

以上即为 PHP 5.6.23 编译安装 BCMath 扩展的完整步骤。希望本教程能为您的开发工作提供参考,感谢支持。如需了解更多技术细节,请参阅相关链接。

上一篇
利用代理服务解决微信授权回调域名单一限制

微信公众号网页授权回调域名仅支持配置一个全域名,导致多子域名拆分的应用无法直接使用。通过引入独立的代理服务(如proxy.your.com),将公众号授权域名指向该代理,由代理统一接收回调并转发至各业务子域,从而突破域名限制,实现同一公众号下多个子应用的登录与支付集成。

下一篇
PHP使用PHPExcel库导出Excel文件的方法

本文介绍在PHP环境中利用PHPExcel库生成并输出Excel文件的完整流程。通过封装getExcel函数,接收文件名、表头数组及数据集合参数,自动加载核心类与Writer组件,配置单元格内容后调用save方法将结果发送至浏览器进行下载。该方法适用于基于ThinkPHP框架的项目,解决了后台数据报表导出的常见需求。

相关文章

更多
PHP 读取 MySQL DECIMAL 后怎样精确合计金额

对账脚本从 MySQL 读取 DECIMAL 金额后若转为 float 求和,大额或跨批次累计时易出现一分误差。解决核心在于保持数据为字符串类型,利用 PHP 8.2 的 BCMath 扩展进行显式精度的累加。通过 SQL CAST 或应用层校验确保输入格式,避免浮点转换导致的精度丢失,并需明确舍入规则及边界检查。

2025.04.13 973
CentOS下安装Apache及依赖组件配置指南

在CentOS Basic Server环境下通过源码编译安装Apache 2.4.9时,常因缺失APR、APR-Util及PCRE等基础库导致configure报错。本文详细记录从下载稳定版httpd包开始,依次安装apr-1.5.1、apr-util-1.5.3和pcre-8.35的过程,并通过指定--with-apr、--with-pcre等参数解决依赖查找失败问题,最终完成Apache的编译启动及开机自启配置。

2026.11.13 931
Nginx编译安装及常用参数详解

本文介绍了基于Ansible Role自动化部署Nginx的方法,并详细解析了./configure编译安装过程中的各类参数。内容涵盖通用配置选项、默认开启与未开启的模块控制(如SSL、HTTP/2、Stream等)、Perl及邮件模块相关设置,帮助管理员根据需求定制Nginx功能。

2025.07.26 893
Aliyun Linux 编译安装 Tengine 2.3.2 详解

本文详细介绍在 Aliyun Linux 环境下编译安装 Tengine(Nginx 分支)的完整流程。涵盖编译环境准备,以及 PCRE、OpenSSL、Zlib、jemalloc 等核心依赖组件的安装配置。同时包含添加专用运行用户、执行 configure 编译参数设置,以及通过 systemd 配置开机自启和常用服务管理命令。

2025.12.13 853
PHP 7.0 Alpha 1 特性解析与编译安装指南

2026年6月11日,PHP官网正式公开发布PHP7第一版的alpha版本。该版本基于新版ZendEngine引擎,相比PHP 5.6性能提升两倍,并引入空接合操作符、标量类型声明等新特性。本文整理PHP 7.0 Alpha 1的安装笔记,涵盖mcrypt依赖、bison与re2c升级以及源码配置编译的具体命令。

2026.07.27 840
PHP Fatal error: Call to undefined function bcmul() 的解决与配置

在Red Hat系统中迁移支付服务器时,因缺少bcmath扩展导致PHP报错Call to undefined function bcmul()。通过执行yum install php-bcmath或针对特定版本的php53-bcmath可修复该问题。若遇到依赖冲突,需先使用yum update更新系统包,再重新安装对应模块以恢复高精度数学计算功能。

2025.05.25 827

专题推荐

更多
PHP 类与对象定义及继承

先看类声明、对象实例与属性访问。理解对象的创建和销毁后,再读继承、方法重载和关键字对照。已有代码遇到继承行为差异时,可进一步查看 final 方法与反射实例。

PHP 定时任务配置与运行

先确定任务运行间隔以及是否允许重叠。固定时间触发先看 Cron 案例,框架内和常驻服务再读对应示例。

Yii2 队列配置与常驻运行

先用一个最小任务跑通入队和消费,再检查 Web 与 Console 是否加载了相同的队列配置。确认命令能手动运行后再配置 Supervisor,最后验证进程重启时的处理情况。

PHP Session 过期时间设置方法

浏览器关闭、服务端回收和业务规定的闲置超时,可能在不同时间发生。对照配置项与应用层时间戳的做法,检查会话何时仍可读、何时应要求重新登录。

PHP URL 编码和解码方法

URL 路径片段和查询参数对空格的处理方式不同。先比较 urlencode 与 rawurlencode,再沿解码过程核对中文、加号和百分号,检查地址是否被重复编码或提前解码。

在线工具箱

更多
键码查询
键码查询

按下键盘按键时查看浏览器记录的键名和事件信息。

.env 配置检查
.env 配置检查

本地检查 .env 键值语法、引号、重复键及空值,预览解析结果,辅助排查 PHP 和 Laravel 环境配置。

进制转换
进制转换

转换二进制、十进制、十六进制等数值表示,辅助程序调试与进制学习。

HTML 标签安全清理
HTML 标签安全清理

清理 HTML 片段中的标签或危险内容,辅助整理待展示的文本。

文件 Base64 转换
文件 Base64 转换

把文件转为 Base64 文本,也可将编码内容还原为文件,方便接口传输与调试。