安装HomeBrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
使用 brew doctor
检查是否存在冲突,然后使用 brew update && brew upgrade
对 brew 进行升级,关于 HomeBrew 更多的使用可以看看: https://bin.zmide.com/?p=277
安装 Nginx
Nginx 在 Mac OS 中可以直接使用 brew 命令进行安装:
brew install nginx
如果需要使用 80 端口的话,需要将 nginx 加入 root 组当中同时设置开机启动:
sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
启动 nginx 服务:
sudo nginx
测试 nginx 是否安装成功,因为默认配置文件监听的是 8080 端口,所以先对 8080 端口发起请求:
curl -IL http://127.0.0.1:8080
结果应该类似于下:
HTTP/1.1 200 OK
Server: nginx/1.9.1
Date: Fri, 29 May 2015 14:50:47 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 29 May 2015 14:40:47 GMT
Connection: keep-alive
ETag: "5444dea7-264"
Accept-Ranges: bytes
安装PHP环境
PHP 在 Mac OS 中可以直接使用 brew 命令进行安装:
brew install php@7.2
安装完成后,还需要将 php 加入环境变量 $PATH 当中:
# 如果使用bash的话
vim ~/.bash_profile
export PATH="/usr/local/sbin:$PATH"
source ~/.bash_profile
# 如果使用ZSH的话
vim ~/.zshrc
export PATH="/usr/local/sbin:$PATH"
source ~/.zshrc
然后可以设置 php-fpm 的开机自启动:
mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/php@7.2/homebrew.mxcl.php@7.2.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php@7.2.plist
使用以下命令监测 php-fpm 是否启动成功:
lsof -Pni4 | grep LISTEN | grep php
如果启动成功应当有以下类似输出 ( 用户不同可能有较小的差异 ) :
bindeMac:~ bin$ sudo lsof -Pni4 | grep LISTEN | grep php-fpm
php-fpm 589 bin 9u IPv4 0x6e563ff015250729 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 590 bin 7u IPv4 0x6e563ff015250729 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 591 bin 7u IPv4 0x6e563ff015250729 0t0 TCP 127.0.0.1:9000 (LISTEN)