Mac 11.0以上版本不能编译PHP的问题

在Mac 11.x版本编译php会提示php.h不存在,phpize也看不出php版本内容:

grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:        
Zend Module Api No:     
Zend Extension Api No: 

这是因为新版本的mac 不在支持php了,后续可能会移除php, 通过php -v 可以看出

但实际上还没有完全移除PHP,可以查看/Library/Developer/CommandLineTools/SDKs目录下你系统版本对应的目录中usr/include/php里面的内容是否还存在,如果还存在说明php devl的头文件还在哪里,只是usr/bin/phpize找不到他们。

通过phpize的输出也不难看出,他是去usr/include/php里面找对应的头文件,那么我们建立软链接到对应的/Library/Developer/CommandLineTools/SDKs下面的php目录即可。但由于/usr/include目录是Read only的,不允许创建软链接,解决办法就是:

1. 把/usr/bin/phpize 和/usr/bin/php-config两个文件复制到/usr/local/bin,并修改如下两处内容,加上local

php-config中extension_dir也重新指定一个目录,并且把/etc/php.ini extension_dir中也同步调整:

2. 建立软连接 ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/usr/include/php /usr/local/include/php

然后使用phpize时指定全路径 /usr/local/bin/phpize

configure时指定我们修改后的php-config:/usr/local/bin/phpize ./configrue –with-php-config=/usr/local/bin/php-config

make, make install 最后把编译的so文件会拷贝到指定的extension_dir目录中


该问题解决后,可通过pear的方式来安装其他pecl 扩展了

1. 下载pear: https://pear.php.net/go-pear.phar
2. 安装: php go-pear.phar,在出现的页面中分别把1,4两步设置为如下图所示,这其实是让pecl命令在bin目录中
3. 然后就可以通过pecl按照扩展了,比如pecl install zip,会下载源码并编译,同上面的phpize & configure & make & make install