1. 程式人生 > >[樂意黎原創]Centos主機動態安裝PHP的bcmath,Libmcrypt,mhash,mcrypt等擴充套件模組方法

[樂意黎原創]Centos主機動態安裝PHP的bcmath,Libmcrypt,mhash,mcrypt等擴充套件模組方法

如下,Centos裡啟動 php-fpm 時,控制檯總在拋若干警告。

[[email protected]] #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 下執行)


控制檯操作步驟:

[[email protected] ext]# cd /usr/local/src/php-7.2.11/ext/bcmath
[[email protected]chi bcmath]# ls
bcmath.c   config.m4   CREDITS    package.xml   tests
bcmath.lo  config.w32  libbcmath  php_bcmath.h
[[email protected] bcmath]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
[[email protected] 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
[[email protected] 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