[乐意黎原创]Centos主机动态安装PHP的bcmath,Libmcrypt,mhash,mcrypt等扩展模块方法

版权声明:本文若为 {aerchi/乐意黎} 原创文章,未经允许不得镜像、采集博客内容。如有转载, 请务必注明来源。 https://blog.csdn.net/aerchi/article/details/84646179

如下,Centos里启动 php-fpm 时,控制台总在抛若干警告。

[root@aerchi] #service php-fpm start

Starting php-fpm daemon is success[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'curl' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/curl (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/curl: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/curl.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/curl.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'bcmath.so' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/bcmath.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/bcmath.so: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/bcmath.so.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/bcmath.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'fileinfo' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/fileinfo (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/fileinfo: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/fileinfo.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/fileinfo.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'mbstring' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/mbstring (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/mbstring: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/mbstring.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/mbstring.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'mysqli' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/mysqli (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/mysqli: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/mysqli.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/mysqli.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'openssl' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/openssl (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/openssl: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/openssl.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/openssl.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/pdo_mysql (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/pdo_mysql: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/pdo_mysql.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/pdo_mysql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'bcmath.so' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/bcmath.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/bcmath.so: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/bcmath.so.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/bcmath.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'curl.so' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/curl.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/curl.so: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/curl.so.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/curl.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'fileinfo.so' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/fileinfo.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/fileinfo.so: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/fileinfo.so.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/fileinfo.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'json.so' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/json.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/json.so: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/json.so.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/json.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'mcrypt.so' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/mcrypt.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/mcrypt.so: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/mcrypt.so.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/mcrypt.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'phar.so' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/phar.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/phar.so: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/phar.so.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/phar.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'zip.so' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/zip.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/zip.so: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/zip.so.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/zip.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[28-Nov-2018 17:45:40] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)

接触 Centos主机没多长时间, 总结这久,安装php时参考了别人的配置,编译php时没有开启若干扩展(很大的一个坑啊).

在实际使用中抛错了,再想添加扩展,然而不想卸载后再重装。

这下就需要用到phpize来帮忙了。

比如增加bcmath扩展的支持,这是一个支持大整数计算的扩展。

由于windows系统是自带而且内置,linux“本类函数仅在 PHP 编译时配置了 --enable-bcmath 时可用”(引号内是手册中的话)


PHP 版本: php-7.2.11, 

PHP源文件路径: /usr/local/src/php-7.2.11

PHP的安装后路径: /usr/local/php/
php.ini 文件路径:  /etc/php.ini

对应的模块.ini 文件路径: /etc/php.d/

php-config 路径: /usr/local/php/bin/php-config

扩展模块安装路径:   /usr/local/php/lib/php/extensions/no-debug-zts-20170718


解决方法:

1. 进入源文件路径目录:  cd /usr/local/src/php-7.2.11/ext

2.  进入bcmath目录(安装其它模块,换成其它模块名称即可): cd  bcmath 

3. 然后执行输入:    /usr/local/php/bin/phpize

4. 然后再执行:    ./configure --with-php-config=/usr/local/php/bin/php-config

5. 执行命令:  make && make install

注:(基于安装bcmatch, 以上命令均在 /usr/local/src/php-7.2.11/ext/bcmath 下执行)


控制台操作步骤:

[root@aerchi ext]# cd /usr/local/src/php-7.2.11/ext/bcmath
[root@aerchi bcmath]# ls
bcmath.c   config.m4   CREDITS    package.xml   tests
bcmath.lo  config.w32  libbcmath  php_bcmath.h
[root@aerchi bcmath]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
[root@aerchi 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-zts-20170718
checking for PHP installed headers prefix... /usr/local/php/include/php
checking if debug is enabled... no
checking if zts is enabled... yes
checking for re2c... re2c
checking for re2c version... 0.14.3 (ok)
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
[root@aerchi bcmath]# make && make install
/bin/sh /usr/local/src/php-7.2.11/ext/bcmath/libtool --mode=link cc -DPHP_ATOM_INC -I/usr/local/src/php-7.2.11/ext/bcmath/include -I/usr/local/src/php-7.2.11/ext/bcmath/main -I/usr/local/src/php-7.2.11/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   -o bcmath.la -export-dynamic -avoid-version -prefer-pic -module -rpath /usr/local/src/php-7.2.11/ext/bcmath/modules  bcmath.lo libbcmath/src/add.lo libbcmath/src/div.lo libbcmath/src/init.lo libbcmath/src/neg.lo libbcmath/src/outofmem.lo libbcmath/src/raisemod.lo libbcmath/src/rt.lo libbcmath/src/sub.lo libbcmath/src/compare.lo libbcmath/src/divmod.lo libbcmath/src/int2num.lo libbcmath/src/num2long.lo libbcmath/src/output.lo libbcmath/src/recmul.lo libbcmath/src/sqrt.lo libbcmath/src/zero.lo libbcmath/src/debug.lo libbcmath/src/doaddsub.lo libbcmath/src/nearzero.lo libbcmath/src/num2str.lo libbcmath/src/raise.lo libbcmath/src/rmzero.lo libbcmath/src/str2num.lo
cc -shared  .libs/bcmath.o libbcmath/src/.libs/add.o libbcmath/src/.libs/div.o libbcmath/src/.libs/init.o libbcmath/src/.libs/neg.o libbcmath/src/.libs/outofmem.o libbcmath/src/.libs/raisemod.o libbcmath/src/.libs/rt.o libbcmath/src/.libs/sub.o libbcmath/src/.libs/compare.o libbcmath/src/.libs/divmod.o libbcmath/src/.libs/int2num.o libbcmath/src/.libs/num2long.o libbcmath/src/.libs/output.o libbcmath/src/.libs/recmul.o libbcmath/src/.libs/sqrt.o libbcmath/src/.libs/zero.o libbcmath/src/.libs/debug.o libbcmath/src/.libs/doaddsub.o libbcmath/src/.libs/nearzero.o libbcmath/src/.libs/num2str.o libbcmath/src/.libs/raise.o libbcmath/src/.libs/rmzero.o libbcmath/src/.libs/str2num.o   -Wl,-soname -Wl,bcmath.so -o .libs/bcmath.so
creating bcmath.la
(cd .libs && rm -f bcmath.la && ln -s ../bcmath.la bcmath.la)
/bin/sh /usr/local/src/php-7.2.11/ext/bcmath/libtool --mode=install cp ./bcmath.la /usr/local/src/php-7.2.11/ext/bcmath/modules
cp ./.libs/bcmath.so /usr/local/src/php-7.2.11/ext/bcmath/modules/bcmath.so
cp ./.libs/bcmath.lai /usr/local/src/php-7.2.11/ext/bcmath/modules/bcmath.la
PATH="$PATH:/sbin" ldconfig -n /usr/local/src/php-7.2.11/ext/bcmath/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/src/php-7.2.11/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-zts-20170718/

以上,提示安装完成,  然后进入  /usr/local/php/lib/php/extensions/no-debug-zts-20170718/  路径 下查看:

成功安装。

最后,别忘记了重启php-fpm, 并重启nginx 或者apache,reload不行,一定要重启.


升级 php 7.2 后,使用微信提供的加解密代码时,提示 call to undefined function mcrypt_module_open() ;大脑疯狂运转1秒钟后,得出结论:php 7.2的扩展有变动;查阅相关资料知晓,mcrypt 扩展从 php 7.1.0 开始废弃;自 php 7.2.0 起,会移到 pecl。还好,安装过程不复杂。
环境:centos 7

  • yum 安装依赖包:

    yum install libmcrypt libmcrypt-devel mcrypt mhash
  • pecl

apt-get install php-pecl


安装Libmcrypt

# cd /usr/local/src
# wget  https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
# tar -zxvf libmcrypt-2.5.8.tar.gz 
# cd libmcrypt-2.5.8 
# /usr/local/php5/bin/phpize #动态编译php模块,使其可以使用configure编译。 
# ./configure --with-php-config=/usr/local/php/bin/php-config 
# make && make install
# libmcript默认安装在/usr/local

安装mhash

Mhash是基于离散数学原理的不可逆向的php加密方式扩展库,其在默认情况下不开启。mhash的可以用于创建校验数值,消息摘要,消息认证码,以及无需原文的关键信息保存(如密码)等。

# cd /usr/local/src
# wget  https://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz/download
# tar -zxvf mhash-0.9.9.9.tar.gz 
# cd mhash-0.9.9.9 
# /usr/local/php5/bin/phpize  
# ./configure --with-php-config=/usr/local/php/bin/php-config 
# make  &&  make install

安装mcrypt
Mcrypt 扩展库可以实现加密解密功能,就是既能将明文加密,也可以密文还原。PHP加密扩展库Mcrypt的算法和加密模式.
 

# cd /usr/local/src
---------------------
# wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download 
# tar -zxvf mcrypt-2.6.8.tar.gz 
# cd mcrypt-2.6.8 
或
# wget http://pecl.php.net/get/mcrypt-1.0.1.tgz
# tar xf mcrypt-1.0.1.tgz
# cd mcrypt-1.0.1
-------------------
# /usr/local/php/bin/phpize  
# ./configure --with-php-config=/usr/local/php/bin/php-config 
# make && make install 


安装完毕,按照编译安装后的提示


ps -ef|grep nginx # 查看nginx 进程

#php-fpm
pkill -9 php-fpm
service php-fpm stop
service php-fpm start

#nginx
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx -s reload  

/usr/local/nginx/sbin/nginx //启动

#apache
apachectl stop
apachectl start


注:比如,zip,  phar,  fileinfo 模块安装也是类似, 只需将 解决方法 (2) 里的模块路径 分别换成 zip, phar, fileinfo, 并执行3、4、5步即可。


其它方法: 

1. 打开/usr/local/php/bin/php-config注释掉:extension_dir='/usr/local/php/lib/php/extensions/no-debug-zts-20170718/'解决的

网上的解决方法是打开/usr/local/php/bin/php-config
注释掉:extension_dir='/usr/local/php/lib/php/extensions/no-debug-zts-20170718/',
但是无效,最终解决方式删除  /etc/php.d  下的对应的 .ini 报错文件!!!

2. 将/etc/php.d/ 目录下的.ini文件全部重命名为.so文件, 或删除对应的  *.ini 文件

如:cp /etc/php.d/zip.ini /etc/php.d/zip.so

若有扩展被重复加载了,打开/etc/php.ini文件,注释扩展加载的地方即可

vi /etc/php.ini # 将redis、memcache、swoo加载的地方注释即可
/etc/init.d/php-fpm restart

3. 其它:

PHP 目录结构: 

1. build 和编译有关的目录。

2. ext 扩展库代码,例如 mysql、zlib、iconv 等我们熟悉的扩展库。其中/ext/standard/目录下是常用的标准函数集。

3. main 主目录包含主要的 PHP 宏和定义。

4. sapi 和各种服务器的接口调用,例如apache、IIS等,也包含一般的fastcgi、cgi等。

5. win32 和 Windows 下编译 PHP 有关的脚本。

6. Zend 文件夹核心的引擎,所有的 Zend API 定义与宏等。

7. scripts Linux 下的脚本目录。

8. tests 测试脚本目录

9. sapi 各类 Web 服务器的接口。

10.TSRM Zend 和 PHP 的 “线程安全资源管理器” (TSRM) 目录。

11.pear 这个目录就是“PHP 扩展与应用仓库”的目录。包含了PEAR 的核心文件。

其中几个重要的文件绝对值得你共时间去了解:

php-src/main/php.h, 位于PHP 主目录。这个文件包含了绝大部分 PHP 宏及 API 定义。

php-src/Zend/zend.h, 位于 Zend 主目录。这个文件包含了绝大部分 Zend 宏及 API定义。

php-src/Zend/zend_API.h, 也位于 Zend 主目录,包含了Zend API的定义 


PHP 安装,详见:   https://blog.csdn.net/aerchi/article/details/72777795


乐意黎

2018-11-30

本文地址: https://blog.csdn.net/aerchi/article/details/84646179

猜你喜欢

转载自blog.csdn.net/aerchi/article/details/84646179
今日推荐