Mac os x下配置nginx + php

一直都没使用过PHP的,最近leader推荐使用他在维护的一个移动端的js框架,在本地合并压缩使用的是php环境处理的,so,只能是搭一个PHP的环境了。一直使用的本地代理服务器都是nginx,虽然PHP和Apache挺般配的,Mac上也自带Apache,但是本地的静态服务一直都是用的nginx,不想在换到Apache上,所以就自己将nginx和PHP配了下对。好了废话不说了,开始正文。

首先打个广告,我leader维护的框架:Murloc(两栖怪),以后会做更详细的介绍。

默认我认为你已经安装好了Homebrew和nginx

OS X 10.9搭载的是PHP54,但是与nginx配置起来比较麻烦,所以我使用Homebrew安装PHP5:

①、安装php-fpm

1、brew tap homebrew/dupes  2、brew tap josegonzalez/homebrew-php  3、brew install --without-apache --with-fpm php55  

第3步安装php的时候可能会报下边那样的错:

Error: SHA256 mismatch  Expected: 519ee29e28532782676f3d8e31a808ffbfee383e0279ccc8cbd2b12ed53c2335  Actual: 165907663faf78ae8a056fd4c6b20bdb54f732c7e6103b4b724b277c934ed206  Archive: /Library/Caches/Homebrew/php55-5.5.12

解决办法:删除/Library/Catches/Homebrew/php55-5-5.12,打开/usr/local/Library/Taps/josegonzalez/homebrew-php/Formula/abstract-php-version.rb文件,

将:http://www.php.net/get/php-5.5.12.tar.bz2/from/this/mirror 
改为:http://uk1.php.net/get/php-5.5.12.tar.bz2/from/this/mirror

保存后,重新执行第3步。

②、替换系统自带的PHP54

打开~/.bash_profile,写入:

export PATH="/usr/local/bin:/usr/local/sbin:$PATH"

保存之后重启终端,php -v或者php-fpm -v

好了现在php算是安装成功了。

③、配置nginx

打开/usr/local/etc/nginx/nginx.conf,配置nginx,下边是我的配置:

server {          listen       8080;          server_name  localhost;            #charset koi8-r;            #access_log  logs/host.access.log  main;            location / {              root   html;              index  index.html index.htm index.php;          }            #error_page  404              /404.html;            # redirect server error pages to the static page /50x.html          #          error_page   500 502 503 504  /50x.html;          location = /50x.html {              root   html;          }            # proxy the PHP scripts to Apache listening on 127.0.0.1:80          #          #location ~ \.php$ {          #    proxy_pass   http://127.0.0.1;          #}            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000          #          location ~ \.php$ {             root           html;             fastcgi_pass   127.0.0.1:9000;             fastcgi_index  index.php;             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;             include        fastcgi_params;          }            # deny access to .htaccess files, if Apache's document root          # concurs with nginx's one          #          #location ~ /\.ht {          #    deny  all;          #}      }

nginx的localhost:8080默认指向的是/usr/local/opt/nginx/html目录的, 在该目录下新建一个php文件,例如test.php,

<?php phpinfo();?>

启动nginx服务器,访问http://localhost:8080/test.php,看是否能看到如下图的页面

如果看到了 那么就配置成功了。

最后附上window下的php + nginx的配置:猛戳这里


http://jingpin.jikexueyuan.com/article/49467.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值