Tyrant

我是个废人,贪婪、奢侈、懒惰、厌恶水果和运动,我应该被扔进小黑屋,关个3、5、7年,每天吃残羹剩饭,与蛇虫鼠蚁为伴,出来后百毒不侵,顿悟世间之大智慧,在临死前的最后几年,为自己画上辉煌的句号,然后孤独终老,了此残生。

在Snow Leopard上安装Nginx+PHP-CGI

好久不碰PHP,略感生疏!不过将WEB 前端向PHP 迁移,势在必行!

这里介绍在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 phpinfo(); ?>

 

 

重启php-cgi、nginx,然后访问http://localhost/test.php

若能看到phpinfo表,则最简配置的nginx+php-cgi 开发环境完成。

 

 

 

 

 

 

 

posted on 2010-06-23 03:36  Tyrant  阅读(382)  评论(0编辑  收藏  举报

导航