mac安装php,以及安装扩展

mac安装php,以及安装扩展

远航
2022-04-24 / 0 评论 / 76 阅读 / 正在检测是否收录...

不建议使用mac自带的php

安装brew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
安装php:默认安装brew资源里的最新的
brew install php
安装路径(7.4)
启动:brew services start php
关闭:brew services stop php
重启:brew services restart php
安装路径: /usr/local/etc/php/7.4(我这里是7.4版本)
扩展路径: /usr/local/lib/php/pecl/20190902
#
下面这两个是为了编译redis.so使用:
phpize路径:/usr/local/opt/php@7.4/bin/phpize
php-config路径:/usr/local/opt/php@7.4/bin/php-config
安装扩展,以Redis为例

去官网下载php-redis包

 地址:http://pecl.php.net/package/redis

选择自己需要的版本:我下载的是:redis-5.3.2

编译
1.解压包
2.cd redis-5.3.2
3./usr/local/opt/php@7.4/bin/phpize
4../configure --with-php-config=/usr/local/opt/php@7.4/bin/php-config
5.make && make install
6. 要在/usr/local/etc/php/7.4/php.ini里加上
extension=redis

编译好之后会在当前目录下的modules目录有个redis.so文件

一般编译之后会把该文件自动copy到/usr/local/lib/php/pecl/20190902下

重启php
brew services restart php
注意:在执行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: 
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
解决方法:
1.重启mac电脑,同时按住command+R ,等出现进度条了再松开

2.弹出的界面是否有“实用工具”,有的话就打开实用工具里面的终端,输入:csrutil disable,然后回车

3.重新启动电脑。

4.安装xcode命令行(如果已安装请忽略)
xcode-select--install

5.根目录挂载为可读写
sudo mount -uw /

6.建立软链
sudo ln -s "$(xcrun --show-sdk-path)/usr/include" /usr/include
1

评论

博主关闭了当前页面的评论