PATHの通っていない場所にインストールしたPHP向けの拡張モジュールコンパイル

- `/usr/bin/php`: PHP8.3（APTで入れたもの）
- `/opt/php8.4/bin/php`: PHP8.4 RC1（ソースからビルドしたもの）

という2バージョンが共存しているマシンで、PHP8.4 RC1向けにXdebugをビルドしたかった。
8.4のphpizeを使えば行けるのかと思ったらそうではなかったのでメモ。

<details><summary>普通にphpize+./configureしたときのログ</summary>

```console
~/xdebug-master$ /opt/php8.4/bin/phpize
Configuring for:
PHP Version:             8.4
PHP Api Version:         20240924
Zend Module Api No:      20240924
Zend Extension Api No:   420240924
$ ./configure --prefix=/opt/php8.4
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for gawk... gawk
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether cc accepts -g... yes
checking for cc option to enable C11 features... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking for system library directory... lib
checking if compiler supports -Wl,-rpath,... yes
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20230831 -I/usr/include/php/20230831/main -I/usr/include/php/20230831/TSRM -I/usr/include/php/20230831/Zend -I/usr/include/php/20230831/ext -I/usr/include/php/20230831/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20230831
checking for PHP installed headers prefix... /usr/include/php/20230831
checking if debugging is enabled... no
checking if PHP is built with thread safety (ZTS)... no

Configuring extension
checking whether to enable Xdebug support... yes, shared
checking whether to enable Xdebug developer build flags... no
checking whether to compress profiler files (requires zlib)... yes
checking for supported PHP version... supported (8.3.12)
checking for clock_gettime... yes
checking for clock_gettime_nsec_np... no
checking for gettimeofday... yes
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for netinet/in.h... yes
checking for poll.h... yes
checking for sys/poll.h... yes
checking for linux/rtnetlink.h... yes
checking for res_ninit... no
checking for __res_ninit... yes
checking for res_nclose... no
checking for __res_nclose... yes
checking for cos in -lm... yes
checking for zlib >= 1.2.9... yes

Configuring libtool
checking for a sed that does not truncate output... /usr/bin/sed
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool

Generating files
configure: creating build directories
configure: creating Makefile
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
```

</details>

↓のあたりのログから、`/opt/php8.4`のPHPを見てくれていないことがわかる。

```
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20230831 -I/usr/include/php/20230831/main -I/usr/include/php/20230831/TSRM -I/usr/include/php/20230831/Zend -I/usr/include/php/20230831/ext -I/usr/include/php/20230831/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20230831
checking for PHP installed headers prefix... /usr/include/php/20230831
```

これを変更するには、`./configure`に`--with-php-config=/opt/php8.4/bin/php-config`を渡せばよい。

`php-config`はPHPのバイナリやライブラリがインストールされている各種パスを返してくれるコマンド。

https://www.php.net/manual/ja/install.pecl.php-config.php

`./configure`は`--with-php-config`での指定がなければ`$PATH`から`php-config`を探すため、8.3の`/usr/bin/php-config`を使ってしまう。