Linux インストール php8.1 ZipArchive と最新バージョンの libzip 拡張機能のインストール

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
...
...
...

これら 2 つの拡張機能をインストールする順序は次のとおりです。

①. 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

コマンドを実行して有効にする

ソース ~/.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 を変更

最後に追加

拡張子=zip.so

改訂

zlib.output_compression = オフ

に変更

zlib.output_compression = オン 

  • ソフトリンクを確立する
[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 デーモン]# ./php-fpm start
php-fpm を開始中 [2023 年 4 月 22 日 21:34:57] 通知: PHP メッセージ: PHP 警告: PHP の起動: 動的ライブラリ 'zip.so' を読み込めません(試してみました: /u01/tool/wp/php8/lib/php/extensions/no-debug-non-zts-20210902/zip.so (libzip.so.5: 共有オブジェクト ファイルを開けません: そのようなファイルやディレクトリはありません) 、 /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: 共有オブジェクト ファイルを開けません: そのようなファイルまたはディレクトリはありません)) 行 0 で不明
 です 

問題が解決しました:

/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 ディレクトリ内)。

 

おすすめ

転載: blog.csdn.net/u011837804/article/details/130308915