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的配置:猛戳這里
轉載于:https://www.cnblogs.com/yangfei/p/3717904.html
總結
以上是生活随笔為你收集整理的Mac os x下配置nginx + php的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于HBASE的并行计算架构之rowke
- 下一篇: 白名单 权限认证方法