1、概述
安装前咱们先看下我本地环境
[root@elk php8]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.9 (Maipo)
[root@elk php8]#
[root@elk php8]# ./bin/php -v
PHP 8.1.18 (cli) (built: Apr 17 2023 13:15:17) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.18, Copyright (c) Zend Technologies
[root@elk php8]#
为了避免重复安装,记得先通过 “./bin/php -m ” 确认是否已安装此扩展。
[root@elk php8]# ./bin/php -m
[PHP Modules]
bcmath
calendar
...
...
...
安装这两个扩展的先后顺序:
①、安装zip(ZipArchive),需要先安装libzip扩展
②、安装libzip,需要先安装cmake
下面我就cmake、libzip、zip的先后顺序安装。
2、安装cmake
在安装cmake之前先确认是否已安装,防止重复安装,命令:“cmake --version”
[root@elk wp]# cmake --version
bash: cmake: 未找到命令...
相似命令是: 'make'
[root@elk wp]#
官网地址:CMake
下载命令:“wget https://github.com/Kitware/CMake/releases/download/v3.26.3/cmake-3.26.3.tar.gz”
[root@elk wp]# ll cmake-3.26.3.tar.gz
-rw-r--r-- 1 root root 10668855 4月 22 19:44 cmake-3.26.3.tar.gz
# 解压
[root@elk wp]# tar -zxvf cmake-3.26.3.tar.gz
# 进入解压目录
[root@elk wp]# cd cmake-3.26.3/
# 1、执行bootstrap命令
[root@elk cmake-3.26.3]# ./bootstrap
-- Checking for curses support
-- Checking for curses support - Failed
-- Looking for a Fortran compiler
-- Looking for a Fortran compiler - /usr/bin/f95
-- Performing Test run_pic_test
-- Performing Test run_pic_test - Success
-- Performing Test run_inlines_hidden_test
-- Performing Test run_inlines_hidden_test - Success
-- Configuring done (50.0s)
-- Generating done (1.2s)
-- Build files have been written to: /u01/tool/wp/cmake-3.26.3
---------------------------------------------
CMake has bootstrapped. Now run gmake.
# 2、make && make install
-- Installing: /usr/local/share/cmake-3.26/Templates/Windows/StoreLogo.png
-- Installing: /usr/local/share/cmake-3.26/Templates/Windows/Windows_TemporaryKey.pfx
-- Installing: /usr/local/share/vim/vimfiles/indent
-- Installing: /usr/local/share/vim/vimfiles/indent/cmake.vim
-- Installing: /usr/local/share/vim/vimfiles/syntax
-- Installing: /usr/local/share/vim/vimfiles/syntax/cmake.vim
-- Installing: /usr/local/share/emacs/site-lisp/cmake-mode.el
-- Installing: /usr/local/share/aclocal/cmake.m4
-- Installing: /usr/local/share/bash-completion/completions/cmake
-- Installing: /usr/local/share/bash-completion/completions/cpack
-- Installing: /usr/local/share/bash-completion/completions/ctest
[root@elk cmake-3.26.3]#
检查是否安装成功
[root@elk cmake-3.26.3]# cmake --version
cmake version 3.26.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
[root@elk cmake-3.26.3]#
3、安装libzip
官网:libzip
下载:wget -c https://libzip.org/download/libzip-1.9.2.tar.gz
解压并创建构建目录
[root@elk wp]# tar -zvxf libzip-1.9.2.tar.gz
//进入安装包
[root@elk wp]# cd libzip-1.9.2
//创建build目录
[root@elk wp]# mkdir build && cd build
[root@elk build]# cmake -DCMAKE_INSTALL_PREFIX=/usr/lib64
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
CMake Error: The source directory "/u01/tool/wp/libzip-1.9.2/build" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
// cmake 上级目录
[root@elk build]# cmake ..
-- Looking for getopt
-- Looking for getopt - found
-- Found Perl: /usr/bin/perl (found version "5.16.3")
-- Configuring done (6.5s)
-- Generating done (0.2s)
-- Build files have been written to: /u01/tool/wp/libzip-1.9.2/build
//编译并安装
[root@elk build]# make && make install
-- Installing: /usr/local/share/man/man3/zip_stat_index.3
-- Installing: /usr/local/bin/zipcmp
-- Set runtime path of "/usr/local/bin/zipcmp" to ""
-- Installing: /usr/local/bin/zipmerge
-- Set runtime path of "/usr/local/bin/zipmerge" to ""
-- Installing: /usr/local/bin/ziptool
-- Set runtime path of "/usr/local/bin/ziptool" to ""
安装后需要设置环境变量
编辑文件“~/.bashrc” 添加以下环境变量
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib64/pkgconfig
export PKG_CONFIG_PATH执行命令使之生效
source ~/.bashrc
检查是否安装成功,如果出现以下结果,则为成功
[root@elk build]# pkg-config --libs libzip
-L/usr/local/lib64 -lzip
[root@elk build]#
4、安装lib
- 下载安装包:wget https://pecl.php.net/get/zip
- 解压并进入解压目录
[root@elk wp]# tar -zxvf zip^C
[root@elk wp]#
[root@elk wp]#
[root@elk wp]# cd zip-1.21.1
[root@elk zip-1.21.1]# pwd
/u01/tool/wp/zip-1.21.1
[root@elk zip-1.21.1]# ls
config.m4 config.w32 CREDITS examples LICENSE php5 php7 php73 php74 php8 php81 tests
[root@elk zip-1.21.1]#
解压目录是没有安装文件的,需要通过phpize创建安装文件
- 查找phpize 目录
//我这里phpize 目录为 /u01/tool/wp/php8/bin/phpize
[root@elk zip-1.21.1]# find / -name phpize
/u01/tool/wp/php-8.1.18/scripts/phpize
/u01/tool/wp/php8/bin/phpize
- 创建安装文件
[root@elk zip-1.21.1]# /u01/tool/wp/php8/bin/phpize
Configuring for:
PHP Api Version: 20210902
Zend Module Api No: 20210902
Zend Extension Api No: 420210902
[root@elk zip-1.21.1]# ls
# 可以看出 执行后 有了configure 文件
autom4te.cache config.h.in configure config.w32 examples php5 php73 php8 run-tests.php
build config.m4 configure.ac CREDITS LICENSE php7 php74 php81 tests
[root@elk zip-1.21.1]#
- 查找php-config安装目录
[root@elk zip-1.21.1]# find / -name php-config
/u01/tool/wp/php-8.1.18/scripts/php-config
/u01/tool/wp/php8/bin/php-config
- 配置
[root@elk zip-1.21.1]# ./configure --with-php-config=/u01/tool/wp/php8/bin/php-config
.....
.....
creating libtool
appending configuration tag "CXX" to libtool
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
- 编译+安装
[root@elk zip-1.21.1]# make && make install
....
....
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: /u01/tool/wp/php8/lib/php/extensions/no-debug-non-zts-20210902/
- 查看是否有zip.so文件
我们本地so文件地址:
[root@elk zip-1.21.1]# find / -name zip.so
/u01/tool/wp/php8/lib/php/extensions/no-debug-non-zts-20210902/zip.so
/u01/tool/wp/zip-1.21.1/modules/zip.so
/u01/tool/wp/zip-1.21.1/.libs/zip.so
[root@elk zip-1.21.1]#
- 更改php.ini
在最后添加
extension=zip.so
修改
zlib.output_compression = Off
改为
zlib.output_compression = On
- 建立软连接
[root@elk daemon]# ln -s /u01/tool/wp/php8/lib/php/extensions/no-debug-non-zts-20210902/zip.so /usr/lib64/zip.so && ldconfig
[root@elk daemon]#
[root@elk daemon]#
[root@elk daemon]# ln -s /u01/tool/wp/php8/lib/php/extensions/no-debug-non-zts-20210902/zip.so /usr/lib/zip.so && ldconfig
[root@elk daemon]#
[root@elk daemon]#
[root@elk daemon]# ldconfig /usr/local/lib64
[root@elk daemon]#
[root@elk daemon]# ldconfig /usr/local/lib
- 重启php
启动报错,解决中.....
[root@elk daemon]# ./php-fpm start
Starting php-fpm [22-Apr-2023 21:34:57] NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library 'zip.so' (tried: /u01/tool/wp/php8/lib/php/extensions/no-debug-non-zts-20210902/zip.so (libzip.so.5: cannot open shared object file: No such file or directory), /u01/tool/wp/php8/lib/php/extensions/no-debug-non-zts-20210902/zip.so.so (/u01/tool/wp/php8/lib/php/extensions/no-debug-non-zts-20210902/zip.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
done
问题解决:
编辑/etc/ld.so.conf文件把库文件目录加上,关闭php-fpm,然后重启即可
vim /etc/ld.so.conf
include ld.so.conf.d/*.conf # 默认只有这一行
/usr/lib64
/usr/lib
/usr/local/lib
/usr/local/lib64
5、检查扩展是否安装成功
通过“php -m” (在php安装目录的bin目录中)检查扩展是否安装成功