posts - 6,  comments - 1,  views - 11049

一直都没使用过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
2
3
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的配置:猛戳这里

posted on   fei.yang  阅读(1673)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示