使用alpine基础镜像,给源码安装的php,增加sockets扩展遇到的问题。

前言

前段时间使用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

总结

最后,希望这个记录能帮助遇到类似问题的同学。

  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ayzen1988

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值