GCEのCentOS8にPHP7.4をビルドしようとして苦労した話

## 結論

PHP7.4をconfigureオプション`--with-openssl`や`--with-pgsql`ありでビルドする場合、メジャー及びマイナーバージョンが同じなら、OSバンドルとソースビルドでインストールしたOpenSSLを共存させてはならない。

## 環境

- CentOS Linux release 8.2.2004 (Core) ...GCPのCompute Engineを使用
- OpenSSL 1.1.1c FIPS  28 May 2019 ...OSバンドル, 標準でインストール済

## OpenSSLのビルド

最新のOpenSSL(当時1.1.1h)をインストールしたく、以下のようにビルド＆インストール

```shell-session
$ sudo dnf install wget
$ wget https://www.openssl.org/source/openssl-1.1.1h.tar.gz
$ tar zxvf openssl-1.1.1h.tar.gz
$ cd openssl-1.1.1h/
$ sudo dnf install perl gcc
$ ./config -fPIC shared --prefix=/usr/local/openssl --openssldir=/usr/local/ssl
$ make
$ make test
$ sudo make install
```

なお、ここでは割愛しますが、Apache2.4.46もあわせてビルド＆インストール。
以下はその際にインストールしたパッケージ

```shell-session
$ sudo dnf install bzip2 expat-devel pcre-devel
```

## PHP7.4のビルド

### 必要パッケージのインストール

```shell-session
$ sudo dnf install libxml2-devel sqlite-devel oniguruma-devel libpq-devel
```

### ビルド

```shell-session
$ wget https://www.php.net/distributions/php-7.4.12.tar.bz2
$ tar xvf php-7.4.12.tar.bz2
$ cd php-7.4.12
$ ./configure \
  --with-config-file-path=/etc/php7 \
  --enable-mbstring \
  --with-apxs2=/usr/local/apache2.4/bin/apxs \
  --with-pgsql \
  --with-zlib-dir \
  --disable-ipv6 \
  --with-openssl \
  OPENSSL_CFLAGS=-I/usr/local/openssl/include \
  OPENSSL_LIBS=-L/usr/local/openssl/lib
$ make
```

## 苦労の始まり...

### 第一の壁

以下のエラーに遭遇

```shell-session
/usr/local/src/php-7.4.12/ext/pgsql/pgsql.c: In function ‘zif_pg_last_oid’:
/usr/local/src/php-7.4.12/ext/pgsql/pgsql.c:3143:27: error: assignment to expression with array type
  Z_STRVAL_P(return_value) = (char *) PQoidStatus(pgsql_result);
                           ^
・
・
/usr/local/src/php-7.4.12/ext/pgsql/pgsql.c: In function ‘zif_pg_copy_to’:
/usr/local/src/php-7.4.12/ext/pgsql/pgsql.c:4174:11: error: ‘ret’ undeclared (first use in this function); did you mean ‘recv’?
      if ((ret = PQgetline(pgsql, copybuf, COPYBUFSIZ))) {
           ^~~
           recv
・
・
make: *** [Makefile:1101: ext/pgsql/pgsql.lo] Error 1
```

ソースに問題があると思ったのですが、同じ手順を以下環境で実行しても再現せず。

- CentOS Linux release 7.8.2003 (Core) ...GCPのCompute Engineを使用
- OpenSSL 1.0.2k-fips  26 Jan 2017 ...OSバンドル, 標準でインストール済

一旦、gccのバージョン違いによるところだろうと勝手に解釈

- CentOS7：gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
- CentOS8：gcc (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5)

回避策を調査していたところ、以下のサイトに出会う

[CentOS 8で様々なバージョンのGCCをビルドしてみた - Qiita](https://qiita.com/tukiyo3/items/d2b886db0288eac3a271)

この情報によると、言語規格のデフォルト指定がgccのバージョンによって違うとのこと。
早速、gcc 4.8.5でデフォルト指定となっていた-std=gnu89で再ビルドしてみる

```shell-session
$ ./configure \
  --with-config-file-path=/etc/php7 \
  --enable-mbstring \
  --with-apxs2=/usr/local/apache2.4/bin/apxs \
  --with-pgsql \
  --with-zlib-dir \
  --disable-ipv6 \
  --with-openssl \
  OPENSSL_CFLAGS=-I/usr/local/openssl/include \
  OPENSSL_LIBS=-L/usr/local/openssl/lib \
  CFLAGS="-std=gnu89"
$ make
```

しかし、同じエラーが表示され解決できず...
CentOS7と同じバージョンのgccをビルド＆インストールしようかと思いましたが、根本的解決でない気がしたので、エラー箇所を修正して再ビルドしたところ...

### 第二の壁

第一の壁で表示されたエラーは出なくなったものの、以下のエラーに遭遇

```
/usr/bin/ld: ext/openssl/.libs/xp_ssl.o: undefined reference to symbol 'SSL_select_next_proto@@OPENSSL_1_1_0'
//usr/local/openssl/lib/libssl.so.1.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [Makefile:268: sapi/cli/php] Error 1
```

??
以下、エラーが出たコマンド

```
/bin/sh /usr/local/src/php-7.4.12/libtool --silent --preserve-dup-deps --mode=link cc -export-dynamic -I/usr/include -g -O2 -fvisibility=hidden -Wall -Wno-strict-aliasing -DZEND_SIGNALS   -L/usr/local/openssl/lib -L/usr/lib64  -R /usr/local/openssl/lib -R /usr/lib64 ext/date/php_date.lo ext/date/lib/astro.lo ext/date/lib/dow.lo ext/date/lib/parse_date.lo ext/date/lib/parse_tz.lo ext/date/lib/timelib.lo ext/date/lib/tm2unixtime.lo ext/date/lib/unixtime2tm.lo ext/date/lib/parse_iso_intervals.lo ext/date/lib/interval.lo ext/libxml/libxml.lo ext/openssl/openssl.lo ext/openssl/xp_ssl.lo ext/pcre/pcre2lib/pcre2_auto_possess.lo ext/pcre/pcre2lib/pcre2_chartables.lo ext/pcre/pcre2lib/pcre2_compile.lo ext/pcre/pcre2lib/pcre2_config.lo ext/pcre/pcre2lib/pcre2_context.lo ext/pcre/pcre2lib/pcre2_dfa_match.lo ext/pcre/pcre2lib/pcre2_error.lo ext/pcre/pcre2lib/pcre2_jit_compile.lo ext/pcre/pcre2lib/pcre2_maketables.lo ext/pcre/pcre2lib/pcre2_match.lo ext/pcre/pcre2lib/pcre2_match_data.lo ext/pcre/pcre2lib/pcre2_newline.lo ext/pcre/pcre2lib/pcre2_ord2utf.lo ext/pcre/pcre2lib/pcre2_pattern_info.lo ext/pcre/pcre2lib/pcre2_serialize.lo ext/pcre/pcre2lib/pcre2_string_utils.lo ext/pcre/pcre2lib/pcre2_study.lo ext/pcre/pcre2lib/pcre2_substitute.lo ext/pcre/pcre2lib/pcre2_substring.lo ext/pcre/pcre2lib/pcre2_tables.lo ext/pcre/pcre2lib/pcre2_ucd.lo ext/pcre/pcre2lib/pcre2_valid_utf.lo ext/pcre/pcre2lib/pcre2_xclass.lo ext/pcre/pcre2lib/pcre2_find_bracket.lo ext/pcre/pcre2lib/pcre2_convert.lo ext/pcre/pcre2lib/pcre2_extuni.lo ext/pcre/pcre2lib/pcre2_script_run.lo ext/pcre/php_pcre.lo ext/sqlite3/sqlite3.lo ext/ctype/ctype.lo ext/dom/php_dom.lo ext/dom/attr.lo ext/dom/document.lo ext/dom/domerrorhandler.lo ext/dom/domstringlist.lo ext/dom/domexception.lo ext/dom/namelist.lo ext/dom/processinginstruction.lo ext/dom/cdatasection.lo ext/dom/documentfragment.lo ext/dom/domimplementation.lo ext/dom/element.lo ext/dom/node.lo ext/dom/string_extend.lo ext/dom/characterdata.lo ext/dom/documenttype.lo ext/dom/domimplementationlist.lo ext/dom/entity.lo ext/dom/nodelist.lo ext/dom/text.lo ext/dom/comment.lo ext/dom/domconfiguration.lo ext/dom/domimplementationsource.lo ext/dom/entityreference.lo ext/dom/notation.lo ext/dom/xpath.lo ext/dom/dom_iterators.lo ext/dom/typeinfo.lo ext/dom/domerror.lo ext/dom/domlocator.lo ext/dom/namednodemap.lo ext/dom/userdatahandler.lo ext/fileinfo/fileinfo.lo ext/fileinfo/libmagic/apprentice.lo ext/fileinfo/libmagic/apptype.lo ext/fileinfo/libmagic/ascmagic.lo ext/fileinfo/libmagic/cdf.lo ext/fileinfo/libmagic/cdf_time.lo ext/fileinfo/libmagic/compress.lo ext/fileinfo/libmagic/encoding.lo ext/fileinfo/libmagic/fsmagic.lo ext/fileinfo/libmagic/funcs.lo ext/fileinfo/libmagic/is_json.lo ext/fileinfo/libmagic/is_tar.lo ext/fileinfo/libmagic/magic.lo ext/fileinfo/libmagic/print.lo ext/fileinfo/libmagic/readcdf.lo ext/fileinfo/libmagic/softmagic.lo ext/fileinfo/libmagic/der.lo ext/fileinfo/libmagic/buffer.lo ext/filter/filter.lo ext/filter/sanitizing_filters.lo ext/filter/logical_filters.lo ext/filter/callback_filter.lo ext/hash/hash.lo ext/hash/hash_md.lo ext/hash/hash_sha.lo ext/hash/hash_ripemd.lo ext/hash/hash_haval.lo ext/hash/hash_tiger.lo ext/hash/hash_gost.lo ext/hash/hash_snefru.lo ext/hash/hash_whirlpool.lo ext/hash/hash_adler32.lo ext/hash/hash_crc32.lo ext/hash/hash_fnv.lo ext/hash/hash_joaat.lo ext/hash/sha3/generic64lc/KeccakP-1600-opt64.lo ext/hash/sha3/generic64lc/KeccakHash.lo ext/hash/sha3/generic64lc/KeccakSponge.lo ext/hash/hash_sha3.lo ext/iconv/iconv.lo ext/json/json.lo ext/json/json_encoder.lo ext/json/json_parser.lo ext/json/json_scanner.lo ext/mbstring/mbstring.lo ext/mbstring/php_unicode.lo ext/mbstring/mb_gpc.lo ext/mbstring/php_mbregex.lo ext/mbstring/libmbfl/filters/html_entities.lo ext/mbstring/libmbfl/filters/mbfilter_7bit.lo ext/mbstring/libmbfl/filters/mbfilter_ascii.lo ext/mbstring/libmbfl/filters/mbfilter_base64.lo ext/mbstring/libmbfl/filters/mbfilter_big5.lo ext/mbstring/libmbfl/filters/mbfilter_byte2.lo ext/mbstring/libmbfl/filters/mbfilter_byte4.lo ext/mbstring/libmbfl/filters/mbfilter_cp1251.lo ext/mbstring/libmbfl/filters/mbfilter_cp1252.lo ext/mbstring/libmbfl/filters/mbfilter_cp1254.lo ext/mbstring/libmbfl/filters/mbfilter_cp5022x.lo ext/mbstring/libmbfl/filters/mbfilter_cp51932.lo ext/mbstring/libmbfl/filters/mbfilter_cp850.lo ext/mbstring/libmbfl/filters/mbfilter_cp866.lo ext/mbstring/libmbfl/filters/mbfilter_cp932.lo ext/mbstring/libmbfl/filters/mbfilter_cp936.lo ext/mbstring/libmbfl/filters/mbfilter_gb18030.lo ext/mbstring/libmbfl/filters/mbfilter_euc_cn.lo ext/mbstring/libmbfl/filters/mbfilter_euc_jp.lo ext/mbstring/libmbfl/filters/mbfilter_euc_jp_2004.lo ext/mbstring/libmbfl/filters/mbfilter_euc_jp_win.lo ext/mbstring/libmbfl/filters/mbfilter_euc_kr.lo ext/mbstring/libmbfl/filters/mbfilter_euc_tw.lo ext/mbstring/libmbfl/filters/mbfilter_htmlent.lo ext/mbstring/libmbfl/filters/mbfilter_hz.lo ext/mbstring/libmbfl/filters/mbfilter_iso2022_jp_ms.lo ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_2004.lo ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_mobile.lo ext/mbstring/libmbfl/filters/mbfilter_iso2022_kr.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_1.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_10.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_13.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_14.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_15.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_16.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_2.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_3.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_4.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_5.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_6.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_7.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_8.lo ext/mbstring/libmbfl/filters/mbfilter_iso8859_9.lo ext/mbstring/libmbfl/filters/mbfilter_jis.lo ext/mbstring/libmbfl/filters/mbfilter_koi8r.lo ext/mbstring/libmbfl/filters/mbfilter_armscii8.lo ext/mbstring/libmbfl/filters/mbfilter_qprint.lo ext/mbstring/libmbfl/filters/mbfilter_sjis.lo ext/mbstring/libmbfl/filters/mbfilter_sjis_open.lo ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.lo ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.lo ext/mbstring/libmbfl/filters/mbfilter_sjis_2004.lo ext/mbstring/libmbfl/filters/mbfilter_tl_jisx0201_jisx0208.lo ext/mbstring/libmbfl/filters/mbfilter_ucs2.lo ext/mbstring/libmbfl/filters/mbfilter_ucs4.lo ext/mbstring/libmbfl/filters/mbfilter_uhc.lo ext/mbstring/libmbfl/filters/mbfilter_utf16.lo ext/mbstring/libmbfl/filters/mbfilter_utf32.lo ext/mbstring/libmbfl/filters/mbfilter_utf7.lo ext/mbstring/libmbfl/filters/mbfilter_utf7imap.lo ext/mbstring/libmbfl/filters/mbfilter_utf8.lo ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.lo ext/mbstring/libmbfl/filters/mbfilter_uuencode.lo ext/mbstring/libmbfl/filters/mbfilter_koi8u.lo ext/mbstring/libmbfl/mbfl/mbfilter.lo ext/mbstring/libmbfl/mbfl/mbfilter_8bit.lo ext/mbstring/libmbfl/mbfl/mbfilter_pass.lo ext/mbstring/libmbfl/mbfl/mbfilter_wchar.lo ext/mbstring/libmbfl/mbfl/mbfl_convert.lo ext/mbstring/libmbfl/mbfl/mbfl_encoding.lo ext/mbstring/libmbfl/mbfl/mbfl_filter_output.lo ext/mbstring/libmbfl/mbfl/mbfl_ident.lo ext/mbstring/libmbfl/mbfl/mbfl_language.lo ext/mbstring/libmbfl/mbfl/mbfl_memory_device.lo ext/mbstring/libmbfl/mbfl/mbfl_string.lo ext/mbstring/libmbfl/mbfl/mbfl_allocators.lo ext/mbstring/libmbfl/nls/nls_de.lo ext/mbstring/libmbfl/nls/nls_en.lo ext/mbstring/libmbfl/nls/nls_ja.lo ext/mbstring/libmbfl/nls/nls_kr.lo ext/mbstring/libmbfl/nls/nls_neutral.lo ext/mbstring/libmbfl/nls/nls_ru.lo ext/mbstring/libmbfl/nls/nls_uni.lo ext/mbstring/libmbfl/nls/nls_zh.lo ext/mbstring/libmbfl/nls/nls_hy.lo ext/mbstring/libmbfl/nls/nls_tr.lo ext/mbstring/libmbfl/nls/nls_ua.lo ext/pdo/pdo.lo ext/pdo/pdo_dbh.lo ext/pdo/pdo_stmt.lo ext/pdo/pdo_sql_parser.lo ext/pdo/pdo_sqlstate.lo ext/pdo_sqlite/pdo_sqlite.lo ext/pdo_sqlite/sqlite_driver.lo ext/pdo_sqlite/sqlite_statement.lo ext/pgsql/pgsql.lo ext/phar/util.lo ext/phar/tar.lo ext/phar/zip.lo ext/phar/stream.lo ext/phar/func_interceptors.lo ext/phar/dirstream.lo ext/phar/phar.lo ext/phar/phar_object.lo ext/phar/phar_path_check.lo ext/posix/posix.lo ext/reflection/php_reflection.lo ext/session/mod_user_class.lo ext/session/session.lo ext/session/mod_files.lo ext/session/mod_mm.lo ext/session/mod_user.lo ext/simplexml/simplexml.lo ext/simplexml/sxe.lo ext/spl/php_spl.lo ext/spl/spl_functions.lo ext/spl/spl_engine.lo ext/spl/spl_iterators.lo ext/spl/spl_array.lo ext/spl/spl_directory.lo ext/spl/spl_exceptions.lo ext/spl/spl_observer.lo ext/spl/spl_dllist.lo ext/spl/spl_heap.lo ext/spl/spl_fixedarray.lo ext/standard/crypt_freesec.lo ext/standard/crypt_blowfish.lo ext/standard/crypt_sha512.lo ext/standard/crypt_sha256.lo ext/standard/php_crypt_r.lo ext/standard/array.lo ext/standard/base64.lo ext/standard/basic_functions.lo ext/standard/browscap.lo ext/standard/crc32.lo ext/standard/crypt.lo ext/standard/cyr_convert.lo ext/standard/datetime.lo ext/standard/dir.lo ext/standard/dl.lo ext/standard/dns.lo ext/standard/exec.lo ext/standard/file.lo ext/standard/filestat.lo ext/standard/flock_compat.lo ext/standard/formatted_print.lo ext/standard/fsock.lo ext/standard/head.lo ext/standard/html.lo ext/standard/image.lo ext/standard/info.lo ext/standard/iptc.lo ext/standard/lcg.lo ext/standard/link.lo ext/standard/mail.lo ext/standard/math.lo ext/standard/md5.lo ext/standard/metaphone.lo ext/standard/microtime.lo ext/standard/pack.lo ext/standard/pageinfo.lo ext/standard/quot_print.lo ext/standard/rand.lo ext/standard/mt_rand.lo ext/standard/soundex.lo ext/standard/string.lo ext/standard/scanf.lo ext/standard/syslog.lo ext/standard/type.lo ext/standard/uniqid.lo ext/standard/url.lo ext/standard/var.lo ext/standard/versioning.lo ext/standard/assert.lo ext/standard/strnatcmp.lo ext/standard/levenshtein.lo ext/standard/incomplete_class.lo ext/standard/url_scanner_ex.lo ext/standard/ftp_fopen_wrapper.lo ext/standard/http_fopen_wrapper.lo ext/standard/php_fopen_wrapper.lo ext/standard/credits.lo ext/standard/css.lo ext/standard/var_unserializer.lo ext/standard/ftok.lo ext/standard/sha1.lo ext/standard/user_filters.lo ext/standard/uuencode.lo ext/standard/filters.lo ext/standard/proc_open.lo ext/standard/streamsfuncs.lo ext/standard/http.lo ext/standard/password.lo ext/standard/random.lo ext/standard/net.lo ext/standard/hrtime.lo ext/tokenizer/tokenizer.lo ext/tokenizer/tokenizer_data.lo ext/xml/xml.lo ext/xml/compat.lo ext/xmlreader/php_xmlreader.lo ext/xmlwriter/php_xmlwriter.lo TSRM/TSRM.lo main/main.lo main/snprintf.lo main/spprintf.lo main/fopen_wrappers.lo main/alloca.lo main/php_scandir.lo main/php_ini.lo main/SAPI.lo main/rfc1867.lo main/php_content_types.lo main/strlcpy.lo main/strlcat.lo main/explicit_bzero.lo main/mergesort.lo main/reentrancy.lo main/php_variables.lo main/php_ticks.lo main/network.lo main/php_open_temporary_file.lo main/output.lo main/getopt.lo main/php_syslog.lo main/streams/streams.lo main/streams/cast.lo main/streams/memory.lo main/streams/filter.lo main/streams/plain_wrapper.lo main/streams/userspace.lo main/streams/transports.lo main/streams/xp_socket.lo main/streams/mmap.lo main/streams/glob_wrapper.lo Zend/zend_language_parser.lo Zend/zend_language_scanner.lo Zend/zend_ini_parser.lo Zend/zend_ini_scanner.lo Zend/zend_alloc.lo Zend/zend_compile.lo Zend/zend_constants.lo Zend/zend_dtrace.lo Zend/zend_execute_API.lo Zend/zend_highlight.lo Zend/zend_llist.lo Zend/zend_vm_opcodes.lo Zend/zend_opcode.lo Zend/zend_operators.lo Zend/zend_ptr_stack.lo Zend/zend_stack.lo Zend/zend_variables.lo Zend/zend.lo Zend/zend_API.lo Zend/zend_extensions.lo Zend/zend_hash.lo Zend/zend_list.lo Zend/zend_builtin_functions.lo Zend/zend_ini.lo Zend/zend_sort.lo Zend/zend_multibyte.lo Zend/zend_ts_hash.lo Zend/zend_stream.lo Zend/zend_iterators.lo Zend/zend_interfaces.lo Zend/zend_exceptions.lo Zend/zend_strtod.lo Zend/zend_gc.lo Zend/zend_closures.lo Zend/zend_weakrefs.lo Zend/zend_float.lo Zend/zend_string.lo Zend/zend_signal.lo Zend/zend_generators.lo Zend/zend_virtual_cwd.lo Zend/zend_ast.lo Zend/zend_objects.lo Zend/zend_object_handlers.lo Zend/zend_objects_API.lo Zend/zend_default_classes.lo Zend/zend_inheritance.lo Zend/zend_smart_str.lo Zend/zend_cpuinfo.lo Zend/zend_execute.lo main/internal_functions_cli.lo sapi/cli/php_cli.lo sapi/cli/php_http_parser.lo sapi/cli/php_cli_server.lo sapi/cli/ps_title.lo sapi/cli/php_cli_process_title.lo \
-lpq -lrt -lrt -lm -ldl -lxml2 -lsqlite3 -lxml2 -lonig -lsqlite3 -lxml2 -lxml2 -lxml2 -lxml2  -o sapi/cli/php
```

よく見ると`-lpq -lrt -lrt -lm -ldl -lxml2 -lsqlite3 -lxml2 -lonig -lsqlite3 -lxml2 -lxml2 -lxml2 -lxml2`に`-lssl -lcrypto`が含まれていない（あと、何故`-lxml2`がこんなにあるのか？）
configureヘルプをよく読む

```shell-session
./configure -h
・
・
Some influential environment variables:
・
・
OPENSSL_LIBS
            linker flags for OPENSSL, overriding pkg-config
・
・
```

`linker flags for OPENSSL`とあるので、LIBディレクトリを指すだけでは不足なのだろうと解釈
`OPENSSL_LIBS="-L/usr/local/openssl/lib -lssl -lcrypto"`に変更して再ビルド

```shell-session
$ ./configure \
  --with-config-file-path=/etc/php7 \
  --enable-mbstring \
  --with-apxs2=/usr/local/apache2.4/bin/apxs \
  --with-pgsql \
  --with-zlib-dir \
  --disable-ipv6 \
  --with-openssl \
  OPENSSL_CFLAGS=-I/usr/local/openssl/include \
  OPENSSL_LIBS="-L/usr/local/openssl/lib -lssl -lcrypto" \
$ make
```

結果は...

### 第三の壁

別のエラーに遭遇

```
ext/pgsql/.libs/pgsql.o: In function `zif_pg_copy_from':
/usr/local/src/php-7.4.12/ext/pgsql/pgsql.c:4319: undefined reference to `ZSTR_LVAL'
//usr/lib64/libk5crypto.so.3: undefined reference to `EVP_KDF_derive@OPENSSL_1_1_1b'
//usr/lib64/libk5crypto.so.3: undefined reference to `EVP_KDF_ctrl@OPENSSL_1_1_1b'
//usr/lib64/libk5crypto.so.3: undefined reference to `EVP_KDF_CTX_new_id@OPENSSL_1_1_1b'
//usr/lib64/libk5crypto.so.3: undefined reference to `EVP_KDF_CTX_free@OPENSSL_1_1_1b'
collect2: error: ld returned 1 exit status
make: *** [Makefile:268: sapi/cli/php] Error 1
```

`libk5crypto.so.3`はKerberosに含まれるライブラリ。
`LD_LIBRARY_PATH`で共有ライブラリのパスに`/usr/local/openssl/lib`を加えたり、Kerberosをビルド＆インストールしたりしたが解消されず。
`/etc/ld.so.conf`に`/usr/local/openssl/lib`を追加したり、バンドルのOpenSSLをアンインストールするのは他への影響が懸念されできず。
詰まったところで、OpenSSLのメジャーおよびマイナーバージョンが同じものをバンドルと共存させるのは無理があると諦め、OpenSSL 1.2がリリースされるまではバンドルのOpenSSLを使うことで妥協

## GCEインスタンスを新たに立ち上げ再挑戦

### 事前にインストールしたパッケージ

```
$ sudo dnf install wget perl gcc bzip2 expat-devel pcre-devel openssl-devel libxml2-devel sqlite-devel oniguruma-devel libpq-devel
```

### PHP7.4のビルド＆インストール

OpenSSLはビルド＆インストールせずにPHPをビルド＆インストール

```shell-session
$ wget https://www.php.net/distributions/php-7.4.12.tar.bz2
$ tar xvf php-7.4.12.tar.bz2
$ cd php-7.4.12
$ ./configure \
  --with-config-file-path=/etc/php7 \
  --enable-mbstring \
  --with-apxs2=/usr/local/apache2.4/bin/apxs \
  --with-pgsql \
  --with-zlib-dir \
  --disable-ipv6 \
  --with-openssl \
  OPENSSL_CFLAGS=-I/usr/include/openssl \
  OPENSSL_LIBS="-L/usr/lib64 -lssl -lcrypto"
$ make
$ make test
$ sudo make install
$ php -v
HP 7.4.12 (cli) (built: Nov  4 2020 16:41:02) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
```

ようやく、PHP7.4のビルド＆インストールが完了