mac m1 下搭建 php 开发环境
一番挣扎之后,还是下手了 m1,真香。

homebrew 安装
1 | /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" |
网慢的话,host 加映射。
1 | 199.232.68.133 raw.githubusercontent.com |
php 安装
看到好多人说,要把自带的 php 先卸载掉, 但是我折腾一圈发现,卸着太麻烦,不卸也没啥问题。
1 | brew install php@7.4 |
然后根据输出的信息添加环境变量:
1 | echo 'export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"' >> ~/.zshrc |
如果错过了这些信息,执行以下命令可以再次查看:
1 | brew info php@7.4 |
php-exc 安装
redis
安装扩展需要用到 pecl, 先查看有没有正确安装:
1 | pecl help version |
正常情况下,输出信息应该和 php 版本一致,即 php7.4。
1 | pecl install redis |
mongodb
1 | ln -s /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php@7.4/7.4.16/include/php/ext/pcre/pcre2.h |
xdebug
xdebug3 配置有改动,具体如下:
1 | xdebug.mode = debug |
nginx 安装
1 | brew install nginx |
安装完成后,需要解析 php。
默认文件不动,添加一个新的配置文件:
vi /opt/homebrew/etc/nginx/services/laravel:
1 | server { |
然后重启或刷新 nginx:
1 | brew services reload nginx || brew services restart nginx |
重启以后,记得改下 hosts,把域名加到映射。
1 | vi /etc/hosts |
redis 安装
1 | brew install redis |
composer 安装
1 | php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 M-finder!
评论
