前言
前段时间使用alpine基础镜像,安装了nginx+php,但是源码安装php的时候没有开启很多扩展,这几天在实践php和rabbitmq实现延迟队列的时候,需要socket扩展,记录下安装的时候遇到的问题以及解决办法。
使用alpine基础镜像,安装nginx+php,然后构建新基础镜像_nginx:1.25.4-alpine 镜像地址-CSDN博客
一、安装sockets扩展
1、进入php源码扩展目录,执行如下命令。
cd /root/php-8.3.3/ext/sockets
2、安装扩展,执行如下命令。
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
3、安装过程当中报如下错误。
make && make install
/bin/sh /root/php-8.3.3/ext/sockets/libtool --tag=CC --mode=compile cc -I. -I/root/php-8.3.3/ext/sockets -I/root/php-8.3.3/ext/sockets/include -I/root/php-8.3.3/ext/sockets/main -I/root/php-8.3.3/ext/sockets -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -D_GNU_SOURCE -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -DZEND_COMPILE_DL_EXT=1 -c /root/php-8.3.3/ext/sockets/sockets.c -o sockets.lo -MMD -MF sockets.dep -MT sockets.lo
mkdir .libs
cc -I. -I/root/php-8.3.3/ext/sockets -I/root/php-8.3.3/ext/sockets/include -I/root/php-8.3.3/ext/sockets/main -I/root/php-8.3.3/ext/sockets -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -D_GNU_SOURCE -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -DZEND_COMPILE_DL_EXT=1 -c /root/php-8.3.3/ext/sockets/sockets.c -MMD -MF sockets.dep -MT sockets.lo -fPIC -DPIC -o .libs/sockets.o
/root/php-8.3.3/ext/sockets/sockets.c: In function 'zif_socket_set_option':
/root/php-8.3.3/ext/sockets/sockets.c:1973:31: error: array type has incomplete element type 'struct sock_filter'
1973 | static struct sock_filter cbpf[8] = {0};
| ^~~~
/root/php-8.3.3/ext/sockets/sockets.c:1974:30: error: storage size of 'bpfprog' isn't known
1974 | static struct sock_fprog bpfprog;
| ^~~~~~~
/root/php-8.3.3/ext/sockets/sockets.c:1977:11: error: 'SKF_AD_CPU' undeclared (first use in this function)
1977 | case SKF_AD_CPU:
| ^~~~~~~~~~
/root/php-8.3.3/ext/sockets/sockets.c:1977:11: note: each undeclared identifier is reported only once for each function it appears in
/root/php-8.3.3/ext/sockets/sockets.c:1978:11: error: 'SKF_AD_QUEUE' undeclared (first use in this function)
1978 | case SKF_AD_QUEUE:
| ^~~~~~~~~~~~
/root/php-8.3.3/ext/sockets/sockets.c:1979:23: error: 'BPF_LD' undeclared (first use in this function)
1979 | cbpf[0].code = (BPF_LD|BPF_W|BPF_ABS);
| ^~~~~~
/root/php-8.3.3/ext/sockets/sockets.c:1979:30: error: 'BPF_W' undeclared (first use in this function)
1979 | cbpf[0].code = (BPF_LD|BPF_W|BPF_ABS);
| ^~~~~
/root/php-8.3.3/ext/sockets/sockets.c:1979:36: error: 'BPF_ABS' undeclared (first use in this function)
1979 | cbpf[0].code = (BPF_LD|BPF_W|BPF_ABS);
| ^~~~~~~
/root/php-8.3.3/ext/sockets/sockets.c:1980:30: error: 'SKF_AD_OFF' undeclared (first use in this function)
1980 | cbpf[0].k = (uint32_t)(SKF_AD_OFF + k);
| ^~~~~~~~~~
/root/php-8.3.3/ext/sockets/sockets.c:1981:23: error: 'BPF_RET' undeclared (first use in this function)
1981 | cbpf[1].code = (BPF_RET|BPF_A);
| ^~~~~~~
/root/php-8.3.3/ext/sockets/sockets.c:1981:31: error: 'BPF_A' undeclared (first use in this function)
1981 | cbpf[1].code = (BPF_RET|BPF_A);
| ^~~~~
make: *** [Makefile:209: sockets.lo] Error 1
4、尝试了很多解决办法都不行,最终通过下面的方式解决了。
apk add linux-headers libpcap-dev
cd /root/php-8.3.3/ext/sockets
./configure --with-php-config=/usr/local/php/bin/php-config --with-linux-headers=/usr/include/linux
make && make install
总结
最后,希望这个记录能帮助遇到类似问题的同学。