PHP安装BCMath扩展的方法

今天小编就为大家分享一篇关于PHP安装BCMath扩展的方法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧。

编译安装 (PHP-5.6.23)

1.进入PHP源码包目录下的ext/bcmath目录。

[root@192 bcmath]# ls

bcmath.c config.m4 config.w32 CREDITS libbcmath package.xml php_bcmath.h tests

2.执行phpize命令,phpize命令在PHP安装目录的bin目录下,如/usr/local/php/bin/phpize。

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

3.执行./configure --with-php-config=/usr/local/php/bin/php-config。要依据php-config的实际路径。

  1. [root@192 bcmath]# ./configure --with-php-config=/usr/local/php/bin/php-config
  2. checking for grep that handles long lines and -e... /usr/bin/grep
  3. checking for egrep... /usr/bin/grep -E
  4. checking for a sed that does not truncate output... /usr/bin/sed
  5. checking for cc... cc
  6. checking whether the C compiler works... yes
  7. checking for C compiler default output file name... a.out
  8. checking for suffix of executables...
  9. checking whether we are cross compiling... no
  10. checking for suffix of object files... o
  11. checking whether we are using the GNU C compiler... yes
  12. checking whether cc accepts -g... yes
  13. checking for cc option to accept ISO C89... none needed
  14. checking how to run the C preprocessor... cc -E
  15. checking for icc... no
  16. checking for suncc... no
  17. checking whether cc understands -c and -o together... yes
  18. checking for system library directory... lib
  19. checking if compiler supports -R... no
  20. checking if compiler supports -Wl,-rpath,... yes
  21. checking build system type... x86_64-unknown-linux-gnu
  22. checking host system type... x86_64-unknown-linux-gnu
  23. checking target system type... x86_64-unknown-linux-gnu
  24. checking for PHP prefix... /usr/local/php
  25. 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
  26. checking for PHP extension directory... /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226
  27. checking for PHP installed headers prefix... /usr/local/php/include/php
  28. checking if debug is enabled... no
  29. checking if zts is enabled... no
  30. checking for re2c... no
  31. configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
  32. checking for gawk... gawk
  33. checking whether to enable bc style precision math functions... yes, shared
  34. checking for ld used by cc... /usr/bin/ld
  35. checking if the linker (/usr/bin/ld) is GNU ld... yes
  36. checking for /usr/bin/ld option to reload object files... -r
  37. checking for BSD-compatible nm... /usr/bin/nm -B
  38. checking whether ln -s works... yes
  39. checking how to recognize dependent libraries... pass_all
  40. checking for ANSI C header files... yes
  41. checking for sys/types.h... yes
  42. checking for sys/stat.h... yes
  43. checking for stdlib.h... yes
  44. checking for string.h... yes
  45. checking for memory.h... yes
  46. checking for strings.h... yes
  47. checking for inttypes.h... yes
  48. checking for stdint.h... yes
  49. checking for unistd.h... yes
  50. checking dlfcn.h usability... yes
  51. checking dlfcn.h presence... yes
  52. checking for dlfcn.h... yes
  53. checking the maximum length of command line arguments... 1572864
  54. checking command to parse /usr/bin/nm -B output from cc object... ok
  55. checking for objdir... .libs
  56. checking for ar... ar
  57. checking for ranlib... ranlib
  58. checking for strip... strip
  59. checking if cc supports -fno-rtti -fno-exceptions... no
  60. checking for cc option to produce PIC... -fPIC
  61. checking if cc PIC flag -fPIC works... yes
  62. checking if cc static flag -static works... no
  63. checking if cc supports -c -o file.o... yes
  64. checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
  65. checking whether -lc should be explicitly linked in... no
  66. checking dynamic linker characteristics... GNU/Linux ld.so
  67. checking how to hardcode library paths into programs... immediate
  68. checking whether stripping libraries is possible... yes
  69. checking if libtool supports shared libraries... yes
  70. checking whether to build shared libraries... yes
  71. checking whether to build static libraries... no
  72. creating libtool
  73. appending configuration tag "CXX" to libtool
  74. configure: creating ./config.status
  75. config.status: creating config.h

4.执行make && make install。

  1. [root@192 bcmath]# make && make install
  2. /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
  3. mkdir .libs
  4. 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
  5. ... ...
  6. ----------------------------------------------------------------------
  7. Libraries have been installed in:
  8. /home/tools/phptools/php-5.6.23/ext/bcmath/modules
  9. If you ever happen to want to link against installed libraries
  10. in a given directory, LIBDIR, you must either use libtool, and
  11. specify the full pathname of the library, or use the `-LLIBDIR'
  12. flag during linking and do at least one of the following:
  13. - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
  14. during execution
  15. - add LIBDIR to the `LD_RUN_PATH' environment variable
  16. during linking
  17. - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
  18. - have your system administrator add LIBDIR to `/etc/ld.so.conf'
  19. See any operating system documentation about shared libraries for
  20. more information, such as the ld(1) and ld.so(8) manual pages.
  21. ----------------------------------------------------------------------
  22. Build complete.
  23. Don't forget to run 'make test'.
  24. Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/

5.查询,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

6.在Dynamic Extensions配置块下添加一行extension=bcmath.so。

7.重启php服务即可。