在Snow Leopard上安装Nginx+PHP-CGI
这里介绍在Snow Leopard 上打造Nginx+PHP-CGI 开发环境!
有了MacPorts,一切都简单了很多!
安装Nginx
sudo port install nginx
如果你和我一样只想做开发环境,不想每次开机自动启动Nginx的话,执行下面的命令:
sudo launchctl unload -w /Library/LaunchDaemons/org.macports.nginx.plist
初始化配置 Nginx
cd /opt/local/etc/nginx/
cp fastcgi.conf.example fastcgi.conf
cp fastcgi_params.example fastcgi_params
cp nginx.conf.example nginx.conf
启动
sudo /opt/local/sbin/nginx
关闭
sudo /opt/local/sbin/nginx -s quit
重启
sudo /opt/local/sbin/nginx -s reload
安装PHP-CGI
sudo port install php5 +fastcgi fcgi
初始化配置php
cd /opt/local/etc/php5
cp php.ini-development php.ini
启动php-cgi
php-cgi -b 127.0.0.1:8888
调试用,启动一个进程足矣,要想关闭的话,ctrl-c即可。
调整Nginx 配置
location ~ \.php$ { root share/nginx/html; fastcgi_pass 127.0.0.1:8888; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /opt/local/share/nginx/html$fastcgi_script_name; include fastcgi_params; }
注意:
fastcgi_pass 中的地址、端口要与php-cgi 一致
fastcgi_param 中的/opt/local/share/nginx/html,这个路径务必正确,否则会报404错误,提示“No input file specified.”。
编写一个测试文件/opt/local/share/nginx/html/test.php
重启php-cgi、nginx,然后访问http://localhost/test.php
若能看到phpinfo表,则最简配置的nginx+php-cgi 开发环境完成。