声明:该环境是在黑苹果系统下搭建javascript
最近工做环境切换到Mac,因此以OS X Yosemite(10.10.1)为例,记录一下从零开始安装Mac下LNMP环境的过程php
确保系统已经安装xcode,而后使用一行命令安装依赖管理工具Homebrewhtml
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"java
首先加入Homebrew官方的几个软件源mysql
brew tap homebrew/dupes brew tap homebrew/versions brew tap homebrew/php
PHP若是采用默认配置安装,会编译mod_php
模块并只运行在Apache环境下,为了使用Nginx,这里须要编译php-fpm而且禁用apache,主要经过参数--without-fpm --without-apache
来实现。完整的安装指令为nginx
brew install php56 \
--without-snmp \ --without-apache \ --with-debug \ --with-fpm \ --with-intl \ --with-homebrew-curl \ --with-homebrew-libxslt \ --with-homebrew-openssl \ --with-imap \ --with-mysql \ --with-tidy
因为OSX已经自带了PHP环境,所以须要修改系统路径,优先运行brew安装的版本,在~/.bashrc
里加入:git
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
安装完毕后能够经过如下指令启动和中止php-fpmgithub
php-fpm -D killall php-fpm
同时能够将php-fpm加入开机启动sql
ln -sfv /usr/local/opt/php56/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
brew install nginx
安装完毕后能够经过apache
nginx nginx -s quit
启动和关闭,同时也支持重载配置文件等操做
nginx -s reload|reopen|stop|quit
nginx安装后默认监听8080端口,能够访问http://localhost:8080
查看状态。若是要想监听80端口须要root权限,运行
sudo chown root:wheel /usr/local/Cellar/nginx/1.6.2/bin/nginx sudo chmod u+s /usr/local/Cellar/nginx/1.6.2/bin/nginx
并使用root权限启动
sudo nginx
Nginx通常都会运行多个域名,所以这里参考了@fish的方法,按Ubuntu的文件夹结构来存放Nginx的配置文件
mkdir -p /usr/local/var/logs/nginx mkdir -p /usr/local/etc/nginx/sites-available mkdir -p /usr/local/etc/nginx/sites-enabled mkdir -p /usr/local/etc/nginx/conf.d mkdir -p /usr/local/etc/nginx/ssl
编辑Nginx全局配置
配置文件地址:http://www.cnblogs.com/RainLi/p/5355079.html
yii2配置文件示例:http://www.cnblogs.com/RainLi/p/5355084.html
vim /usr/local/etc/nginx/nginx.conf
建议下载MysqlWorkBench
http://www.cnblogs.com/RainLi/p/5355143.html