mac lnmp 环境搭建
声明:该环境是在黑苹果系统下搭建
安装Homebrew
最近工作环境切换到Mac,所以以OS X Yosemite(10.10.1)为例,记录一下从零开始安装Mac下LNMP环境的过程
确保系统已经安装xcode,然后使用一行命令安装依赖管理工具Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安装PHP5.6(FPM方式)
首先加入Homebrew官方的几个软件源
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/php
PHP如果采用默认配置安装,会编译mod_php
模块并只运行在Apache环境下,为了使用Nginx,这里需要编译php-fpm并且禁用apache,主要通过参数--without-fpm --without-apache
来实现。完整的安装指令为
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
里加入:
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
PHP-FPM的加载与启动
安装完毕后可以通过以下指令启动和停止php-fpm
php-fpm -D
killall php-fpm
同时可以将php-fpm加入开机启动
ln -sfv /usr/local/opt/php56/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
安装Nginx
brew install nginx
安装完毕后可以通过
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 + PHP-FPM配置
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全局配置
vim /usr/local/etc/nginx/nginx.conf
配置文件地址:http://www.cnblogs.com/RainLi/p/5355079.html
yii2配置文件示例:http://www.cnblogs.com/RainLi/p/5355084.html
Mysql配置
建议下载MysqlWorkBench
常见问题地址
http://www.cnblogs.com/RainLi/p/5355143.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步