以前換電腦裝了個Mnmp,有遇到一些小坑,寫在這,但願能幫到一些初次搭建Mnmp的phper。php
.
.
.html
Homebrew是一款Mac OS平臺下的軟件包管理工具,擁有安裝、卸載、更新、查看、搜索等不少實用的功能。mysql
安裝Homebrew以前,須要肯定mac是否安裝過xcode,而後安裝xcode命令行工具。nginx
#安裝xcode命令行工具 xcode-select --install
若是該方法你不肯用或者各類緣由,能夠:git
登陸 [https://developer.apple.com/download/more/][1] 而後下載 dmg 安裝
注:必定要選擇和mac系統版本,xcode版本一致的命令行工具。github
好了如今咱們開始安裝Homebrew。sql
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝好了Homebrew以後,即可以使用brew命令來安裝相應的包了。apache
brew install nginx
執行完以後Nginx就安裝好了,如下爲nginx幾個經常使用命令。vim
# 啓動 nginx服務 sudo nginx # 從新加載配置|重啓|中止|退出 nginx nginx -s reload|reopen|stop|quit #測試配置是否有語法錯誤 nginx -t # 啓動 nginx sudo ngixn -c /usr/local/etc/nginx/nginx.conf #測試配置是否有語法錯誤 nginx -t -c /usr/local/etc/nginx/nginx.conf
nginx啓動後,在瀏覽器中輸入http://localhost:8080/,回車便可看到運行結果,顯示的是/usr/local/Cellar/nginx/1.10.0/html/index.html文件的內容。xcode
設置開機自啓動nginx服務設置:
mkdir -p ~/Library/LaunchAgents cp /usr/local/Cellar/nginx/1.10.0/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
brew install mysql
#啓動mysql /usr/local/Cellar/mysql/5.7.12/bin/mysqld #設置密碼 /usr/local/bin/mysqladmin -u root password 'new-password' #登陸mysql mysql -u root -p
設置開機啓動
mkdir -p ~/Library/LaunchAgents/ cp /usr/local/Cellar/mysql/5.7.12/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
brew tap homebrew/php #php擴展 brew install --without-apache --with-fpm --with-mysql php56 ## php-fpm
php設置開機啓動
mkdir -p ~/Library/LaunchAgents cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
vim /usr/local/etc/nginx/nginx.conf #隱藏入口文件配置 location / { index index.php index.html index.htm; if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?$1 last; #ci框架寫法 #rewrite ^/(.*)$ /index.php?s=/$1 last; #tp框架寫法 break; } }
vim /etc/hosts # 127.0.0.1 www.test.com #