Linux installation php8.1 ZipArchive and the latest version of libzip extension installation

1 Overview

Before installing, let's take a look at my local environment

[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]#

In order to avoid repeated installation, remember to confirm whether the extension is installed by "./bin/php -m " first.

[root@elk php8]# ./bin/php -m
[PHP Modules]
bcmath
calendar
...
...
...

The sequence of installing these two extensions:

①. To install zip (ZipArchive), you need to install the libzip extension first.
② To install libzip, you need to install cmake first.

Next, I will install cmake, libzip, and zip in order.

2. Install cmake

Before installing cmake, confirm whether it is installed to prevent repeated installation, command: "cmake --version"

[root@elk wp]# cmake --version
bash: cmake: 未找到命令...
相似命令是: 'make'
[root@elk wp]#

Official website address: CMake

 

Download command: "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]#

 Check if the installation is successful

[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. Install libzip

Official website: libzip

Download: wget -c https://libzip.org/download/libzip-1.9.2.tar.gz
unzip and create build directory

[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 ""


 Environment variables need to be set after installation

Edit the file "~/.bashrc" and add the following environment variables

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib64/pkgconfig
export PKG_CONFIG_PATH

Execute the command to make it effective

source ~/.bashrc

Check whether the installation is successful, if the following results appear, it is successful

[root@elk build]# pkg-config --libs libzip
-L/usr/local/lib64 -lzip
[root@elk build]#

4. Install lib

  • Download the installation package: wget https://pecl.php.net/get/zip
  • Unzip and enter the unzipped directory
[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]#

There is no installation file in the decompression directory, you need to create the installation file through phpize 

  •  Find the phpize directory
//我这里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
  •  Create installation file
[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]#
  • Find the php-config installation directory
[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
  •  configuration
[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
  • compile + install
[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/
  •  Check if there is a zip.so file

Our local so file address:

[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]#
  • change php.ini

Add at the end

extension=zip.so

Revise

zlib.output_compression = Off

changed to

zlib.output_compression = On 

  • Establish a soft link
[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
  • restart php

The startup error is reported, and it is being solved...

[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 

problem solved:

Edit the /etc/ld.so.conf file to add the library file directory, close php-fpm, and then restart

vim /etc/ld.so.conf
include ld.so.conf.d/*.conf  # 默认只有这一行
/usr/lib64
/usr/lib
/usr/local/lib
/usr/local/lib64

5. Check whether the extension is installed successfully

Check whether the extension is installed successfully by "php -m" (in the bin directory of the php installation directory)

 

Guess you like

Origin blog.csdn.net/u011837804/article/details/130308915