homebrew是mac下很是好用的包管理器,會自動安裝相關的依賴包,將你從繁瑣的軟件依賴安裝中解放出來。 安裝homebrew也很是簡單,只要在終端中輸入:php
<!-- lang: shell --> ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
homebrew的經常使用命令:mysql
<!-- lang: shell --> brew update #更新可安裝包的最新信息,建議每次安裝前都運行下 brew search pkg_name #搜索相關的包信息 brew install pkg_name #安裝包
想了解更多地信息,請參看homebrewnginx
安裝git
<!-- lang: shell --> brew search nginx brew install nginx
當前的最新版本是1.4.4
。github
配置sql
<!-- lang: shell --> cd /usr/local/etc/nginx/ mkdir conf.d vim nginx.conf vim ./conf.d/default.conf
nginx.conf內容,shell
<!-- lang: shell --> worker_processes 1; error_log /usr/local/var/log/nginx/error.log warn; pid /usr/local/var/run/nginx.pid; events { worker_connections 256; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /usr/local/var/log/nginx/access.log main; port_in_redirect off; sendfile on; keepalive_timeout 65; include /usr/local/etc/nginx/conf.d/*.conf; }
default.conf文件內容,數據庫
<!-- lang: shell --> server { listen 8080; server_name localhost; root /Users/user_name/nginx_sites/; # 該項要修改成你準備存放相關網頁的路徑 location / { index index.php; autoindex on; } #proxy the php scripts to php-fpm location ~ \.php$ { include /usr/local/etc/nginx/fastcgi.conf; fastcgi_intercept_errors on; fastcgi_pass 127.0.0.1:9000; } }
Mac OSX 10.9的系統自帶了PHP、php-fpm,省去了安裝php-fpm的麻煩。 這裏須要簡單地修改下php-fpm的配置,不然運行php-fpm
會報錯。vim
<!-- lang: shell --> sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf vim /private/etc/php-fpm.conf
修改php-fpm.conf文件中的error_log
項,默認該項被註釋掉,這裏須要去註釋而且修改成error_log = /usr/local/var/log/php-fpm.log
。若是不修改該值,運行php-fpm的時候會提示log文件輸出路徑不存在的錯誤。瀏覽器
安裝
<!-- lang: shell --> brew install mysql
經常使用命令
<!-- lang: shell --> mysql.server start #啓動mysql服務 mysql.server stop #關閉mysql服務
配置 在終端運行mysql_secure_installation
腳本,該腳本會一步步提示你設置一系列安全性相關的參數,包括:設置root密碼
,關閉匿名訪問
,不容許root用戶遠程訪問
,移除test數據庫
。固然運行該腳本前記得先啓動mysql服務。
在以前nginx配置文件default.conf中設置的root
項對應的文件夾下建立測試文件index.php:
<!-- lang: php --> <!-- ~/nginx_sites/index.php --> <?php phpinfo(); ?>
啓動nginx服務,sudo nginx
; 修改配置文件,重啓nginx服務,sudo nginx -s reload
啓動php服務,sudo php-fpm
; 在瀏覽器地址欄中輸入localhost:8080
,若是配置正確地話,應該能看到PHP相關信息的頁面。