Mac用port安装nginx

安装macport

到http://www.macports.org/install.php下载macports
安装nginx:运行

sudo port install nginx spawn-fcgi

安装php:运行

sudo port install php53 fcgi php53-cgi php53-mysql php53-curl php53-iconv php53-mcrypt

安装imagick: 运行

sudo port install php53-imagick

nginx配置
进入

cd /opt/local/etc/nginx

创建sites-avalaible和sites-enabled文件夹
参考附件的配置文件,编辑nginx.conf, fastcgi.conf, mime.types
参考附件的配置文件在sites-available中创建web配置文件

php 配置


 error_reporting = E_ALL & ~E_NOTICE
 display_errors = On
 date.timezone = Asia/Shanghai
 short_open_tag = On



开启自启动配置
将以下代码保存至/Library/LaunchDaemons/org.macports.nginx.plist

 <?xml version='1.0' encoding='UTF-8'?>
 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
 "<span style="text-decoration: underline;">http://www.apple.com/DTDs/PropertyList-1.0.dtd</span>" >
 <plist version='1.0'>
 <dict>
 <key>Label</key><string>org.macports.nginx</string>
 <key>ProgramArguments</key>
 <array>
         <string>/opt/local/bin/daemondo</string>
         <string>--label=nginx</string>
         <string>--start-cmd</string>
         <string>/opt/local/sbin/nginx</string>
         <string>;</string>
         <string>--pid=fileauto</string>
         <string>--pidfile</string>
         <string>/opt/local/var/run/nginx/nginx.pid</string>
 </array>
 <key>Debug</key><false/>
 <key>Disabled</key><true/>
 <key>KeepAlive</key><true/>
 </dict>
 </plist>

将以下代码保存至/Library/LaunchDaemons/org.macports.phpfcgi.plist

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "<span style="text-decoration: underline;">http://www.apple.com/DTDs/PropertyList-1.0.dtd</span>">
 <plist version="1.0">
 <dict>
   <key>Label</key><string>org.macports.phpfcgi</string>
   <key>Debug</key><false />
   <key>OnDemand</key><false />
   <key>RunAtLoad</key><false />
   <key>EnvironmentVariables</key>
   <dict>
     <key>PHP_FCGI_CHILDREN</key><string>2</string>
     <key>PHP_FCGI_MAX_REQUESTS</key><string>5000</string>
   </dict>
   <key>LaunchOnlyOnce</key><true />
   <key>ProgramArguments</key>
   <array>
     <string>/opt/local/bin/spawn-fcgi</string>
     <string>-C 2</string>
     <string>-p 9000</string>
     <string>-f /opt/local/bin/php-cgi53</string>
   </array>
 </dict>
 </plist>

运行

sudo launchctl load -w /Library/LaunchDaemons/org.macports.nginx.plist

运行

sudo launchctl load -w /Library/LaunchDaemons/org.macports.phpfcgi.plist

运行

sudo lsof -i:80

sudo lsof -i:9000

检查nginx和fastcgi是否分别正常监听80和9000端口
如果安装php扩展,安装后重启fastcgi即可

sudo killall php-cgi53
sudo php-cgi53 -b 127.0.0.1:9000  &

发表评论