php

PHP 安装扩展报错 grep: /usr/include/ph

2020-02-24  本文已影响0人  bianruifeng

环境:
Mac os cataline 版本 10.15.3 (19D76)
PHP Version 7.3.11
资源:libzip-1.2.0.tar.gz+zip 提取码: vk6v

安装ZipArchive

wget [http://pecl.php.net/get/zip](http://pecl.php.net/get/zip)
tar -zxvf zip
cd zip-1.x.x
phpize
./configure
make
sudo make instal

执行 phpize命令时遇到:

usermac@ usermac zip-1.17.1 % phpize
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:  

终端
cd /usr
/usr下找不到include文件

Xcode:(如果找不到Xcode.app,先到App Store下载安装)
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include路径下有需要的文件,最好自己cd到路径下查看MacOSX10.15.sdk可能不一样。

直接在终端执行

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include /usr/include

报错:没有权限(即便加了sudo)

ln: /usr/include: Operation not permitted

解决方法:

1、重启mac电脑,同时按住command+r, 出现进度条再松开。

2、弹出界面,选择“实用工具->终端”,输入:csrutil disable,然后回车会有英文提示成功。

3、重新启动电脑

4、进入“终端”,输入

cd /usr
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include /usr/include

提示:系统文件只读

ln: /usr/include: Read-only file system

终端执行:

sudo mount -uw /

然后再执行第4步。
查看/usr/下文件,操作完成。

接着执行phpize命令,报错:

checking for libzip... not found
configure: error: Please reinstall the libzip distribution

需要安装libzip

wget https://libzip.org/download/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make 
sudo make install

之所以下载1.2.0版本,因为更高版本安装时,还需要另外安装cmake 命令。

接着执行phpize命令
当执行 make命令时:

/usr/local/include/zip.h:59:10: fatal error: 'zipconf.h' file not found
#include <zipconf.h>
         ^~~~~~~~~~~
1 error generated.
make: *** [php73/php_zip.lo] Error 1

zipconf.h拷贝过去

 cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

接着执行 make && sudo make install 命令

最后返回一个地址:这个地址下保存了zip.so

Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20180731/

编辑/etc/php.ini (可以通过phpinfo()来查看位置)
zlib.output_compression = Off 改为 zlib.output_compression = On ;
增加extension =/usr/lib/php/extensions/no-debug-non-zts-20180731/zip.so
保存

最后重启一下Apache
sudo apachectl restart

这个zip模块就安装完成了

参考:
PHP如何开启自带的ZipArchive类,实现压缩解压功能
PHP ZipArchive 安装

上一篇 下一篇

猜你喜欢

热点阅读