之前在Windows上开发大部分都是使用的集成环境(xampp,phpstudy,wamp),可以完成日常便捷开发,有些时候却Windows下无法实现的就需要自己搭建虚拟机,在虚拟机中搭建lnmp环境,也可以完成开发工作。同样在Mac也会有这两种选择,可以使用现成的集成开发环境(mamp),但是使用Mac本身有个优势,那就是Mac是Unix系统,所有可以直接在本地搭建lnmp的环境,更加方便的进行开发工作。
1.使用brew包管理器进行安装
1.NGINX安装
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
进行测试
curl -IL http://127.0.0.1:80 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
NGINX相关命令
sudo nginx //启动nginx sudo nginx -s reload|reopen|quit //重新加载|重启|退出
2.PHP安装
1)查看可用的PHP版本
brew search php
2)安装PHP
# 在此我们安装php7.1 如果想安装php5.6等只需要将php71改为php56等 # 安装之前可以查看安装选项 brew options homebrew/php/php71 brew install php71 --whitout-apache --with-imap --with-tidy --with-debug --with-pgsql --with-mysql --with-fpm
3)需要将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
4)设置开机启动
mkdir -p ~/Library/LaunchAgents ln -sfv /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
5)切换PHP版本
brew unlink php@5.6 //删除5.6版本链接 brew link php@7.2 //新建7.2版本链接
6)服务相关命令
brew services start php@7.2 //开启PHP7.2服务
lsof -Pni4 | grep LISTEN | grep php //检测php-fpm是否启动 php-fpm 21819 lixing 8u IPv4 0xe83479551b2f79c5 0t0 TCP 127.0.0.1:9000 (LISTEN) php-fpm 21822 lixing 9u IPv4 0xe83479551b2f79c5 0t0 TCP 127.0.0.1:9000 (LISTEN) php-fpm 21823 lixing 9u IPv4 0xe83479551b2f79c5 0t0 TCP 127.0.0.1:9000 (LISTEN)
3.MySQL安装