🔧

Macでphp8.0.xをphp-buildが'DH_free' has been explicitly marked deprecate

2022/11/18に公開

解決策

  • Homebrewでopenssl@1.1を入れる
    brew install openssl@1.1
  • brew info openssl@1.1
    を実行してパスを確認する
  • ビルド時にLDFLAGS,CPPFLAGS,PKG_CONFIG_PATHパスを通すようにする

ビルド用にシェルスクリプト作成すると楽です。
環境によってパスは異なるので適宜書き換えてください。

build-php8.0.24.sh
export LDFLAGS="-L/opt/homebrew/opt/bzip2/lib:/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/bzip2/include:/opt/homebrew/opt/openssl@1.1/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig:/opt/homebrew/opt/jpeg/lib/pkgconfig:/opt/homebrew/opt/icu4c/lib/pkgconfig:/opt/homebrew/opt/tidy-html5/lib/pkgconfig"
export PHP_BUILD_CONFIGURE_OPTS="--with-sodium --with-pear --without-pcre-jit --with-tidy=/opt/homebrew/opt/tidy-html5 --with-bz2=/opt/homebrew/opt/bzip2 --with-iconv=/opt/homebrew/opt/libiconv"
phpenv install 8.0.24
chmod +x build-php8.0.24.sh
./build-php8.0.24.sh

以下は参考にどうぞ

% brew info openssl@1.1
==> openssl@1.1: stable 1.1.1s (bottled) [keg-only]
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/opt/homebrew/Cellar/openssl@1.1/1.1.1q (8,097 files, 18MB)
  Poured from bottle on 2022-10-27 at 17:22:43
/opt/homebrew/Cellar/openssl@1.1/1.1.1s (8,101 files, 18MB)
  Poured from bottle on 2022-11-13 at 16:59:51
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openssl@1.1.rb
License: OpenSSL
==> Dependencies
Required: ca-certificates ✔
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /opt/homebrew/etc/openssl@1.1/certs

and run
  /opt/homebrew/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

[Compiling]: /var/tmp/php-build/source/8.0.9

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
/opt/homebrew/Cellar/openssl@3/3.0.5/include/openssl/dh.h:200:1: note: 'DH_free' has been explicitly marked deprecated here
OSSL_DEPRECATEDIN_3_0 void DH_free(DH *dh);
^
/opt/homebrew/Cellar/openssl@3/3.0.5/include/openssl/macros.h:182:49: note: expanded from macro 'OSSL_DEPRECATEDIN_3_0'
#   define OSSL_DEPRECATEDIN_3_0                OSSL_DEPRECATED(3.0)
                                                ^
/opt/homebrew/Cellar/openssl@3/3.0.5/include/openssl/macros.h:62:52: note: expanded from macro 'OSSL_DEPRECATED'
#     define OSSL_DEPRECATED(since) __attribute__((deprecated))
                                                   ^
3 warnings generated.
-----------------------------------------

The full Log is available at '/tmp/php-build.8.0.9.20221118144419.log'.
[Warn]: Aborting build.
% brew info openssl@1.1
==> openssl@1.1: stable 1.1.1s (bottled) [keg-only]
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/opt/homebrew/Cellar/openssl@1.1/1.1.1q (8,097 files, 18MB)
  Poured from bottle on 2022-10-27 at 17:22:43
/opt/homebrew/Cellar/openssl@1.1/1.1.1s (8,101 files, 18MB)
  Poured from bottle on 2022-11-13 at 16:59:51
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openssl@1.1.rb
License: OpenSSL
==> Dependencies
Required: ca-certificates ✔
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /opt/homebrew/etc/openssl@1.1/certs

and run
  /opt/homebrew/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

==> Analytics
install: 1,084,339 (30 days), 2,513,776 (90 days), 11,317,722 (365 days)
install-on-request: 48,554 (30 days), 99,246 (90 days), 413,197 (365 days)
build-error: 1,482 (30 days)
amnesia@amnesia ~ %

※8.0.9は、バグあるようなので8.0.29でビルドする。

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
/var/tmp/php-build/source/8.0.9/ext/intl/breakiterator/codepointiterator_internal.h:40:17: error: virtual function 'operator==' has a different return type ('UBool' (aka 'signed char')) than the function it overrides (which has return type 'bool')
                virtual UBool operator==(const BreakIterator& that) const;
                        ~~~~~ ^
/opt/homebrew/Cellar/icu4c/71.1/include/unicode/brkiter.h:127:18: note: overridden virtual function is here
    virtual bool operator==(const BreakIterator&) const = 0;
            ~~~~ ^
1 error generated.
make: *** [ext/intl/breakiterator/codepointiterator_internal.lo] Error 1
1 error generated.
make: *** [ext/intl/breakiterator/codepointiterator_methods.lo] Error 1
-----------------------------------------

https://bugs.php.net/bug.php?id=81592

amnesia@amnesia ~ % openssl version
LibreSSL 2.8.3
↑この環境でビルドにはLibreSSLが使用されてしまうのでパスを通す必要があるという話でした

関連
https://tearoom6.hateblo.jp/entry/2020/05/30/225038

Discussion