Mac os x下配置nginx + php

來源:互聯網
上載者:User

標籤:style   blog   class   code   java   tar   

一直都沒使用過PHP的,最近leader推薦使用他在維護的一個移動端的js架構,在本地合并壓縮使用的是php環境處理的,so,只能是搭一個PHP的環境了。一直使用的本地Proxy 伺服器都是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 mismatchExpected: 519ee29e28532782676f3d8e31a808ffbfee383e0279ccc8cbd2b12ed53c2335Actual: 165907663faf78ae8a056fd4c6b20bdb54f732c7e6103b4b724b277c934ed206Archive: /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的配置:猛戳這裡

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.