mac os maverick下安装nginx+php-fpm via homebrew

自己虽然平时爱折腾,却很少有记下来的习惯,除非碰到特别多问题的部署才会有冲动。今天看同事折腾git,在旁边看着他mac上的evernote满满的记了好几篇,全是技术相关的记录,忽然很感慨。过去解决了很多碎片化的问题,都没有系统地记下来,虽然今后也不能保证,但起码会决心挤出时间来写点东西(现在私人时间多了

 

安装nginx:

mac上好用的软件包管理工具首选homebrew,他家的宣传口号牛逼得很,”mac ports driving you to drink?try home brew“ 记得当时google前还真被macport折磨得要吐

安装nginx很简单 ,brew install nginx 就可以了。其中有个小小提示:Warning: /usr/local/sbin is not in your PATH 只需要在/etc/paths中加入 /usr/local/sbin路径即可

mac自带了apache,默认的apache端口是80,nginx安装后默认是8080,我没有洁癖,没必要两个只能活一个,所以8080端口就留给nginx的测试

要使nginx开机启动,终端命令 launchctl load -w /System/Library/LaunchDaemon/org.apache***.plist *号是忘记了得内容,反正按tab就行 (同理unload可撤销)

配置文件/etc/nginx/nginx.conf 在其中的http内容中加入 include vhost/*.conf 

新建vhost文件夹,这里按{域名}.conf的规则创建virtual host

 

安装php-fpm:

mac本身的php就支持fpm,php info查看fpm是否enable,否则可以用homebrew再装一次:

brew tap homebrew/dupes

brew tap josegonzalez/homebrew-php

然后 brew install php54 --with-fpm --with-mysql --with-tidy --with-debug

出现 configure: error: Cannot find OpenSSL's <evp.h>,homebrew github上有人回答了该问题

 
For future reference of anybody looking for Command Line Tools with Xcode 5, open up a Terminal window and type xcode-select --install. A window will appear informing you command line tools are required. Click Install and you should be good to go

xcode-select --install, 重新安装后通过

启动fpm:php-fpm 提示找不到conf和log,cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf,根据提示的error log路径创建文件或在conf中修改error log路径,运行正常
修改nginx中php fpm的注释,如果配置了vhost则配置文件加入相对的php location内容,script指向root path.

 

开机启动php-fpm

vi /System/Library/LaunchDaemon/org.php.php-fpm.plist:

 

<?xml version="1.0" encoding="UTF-8"?>

 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

 <plist version="1.0">

 <dict>

 <key>Label</key><string>php-fpm</string>

 <key>Program</key><string>/usr/sbin/php-fpm</string>

 <key>KeepAlive</key><true/>

 </dict>

 </plist>

launchctl load -w /System/Library/LaunchDaemon/org.php.php-fpm.plist

 

Thats all.

posted @ 2014-06-22 23:25  KimSky  阅读(3200)  评论(0编辑  收藏  举报