1.卸載mac自帶的apache和php,有用集成環境,建議也刪掉php
先停掉apache:mysql
sudo apachectl stopnginx
而後通通刪掉sql
sudo rm /usr/sbin/httpd
sudo rm -r /etc/apache2/apache
2.安裝Nginxvim
安裝完後,先不急着修改配置文件bash
先設置權限php7
sudo chown root:wheel /usr/local/opt/nginx/bin/nginx
sudo chmod u+s /usr/local/opt/nginx/bin/nginxphp-fpm
若是想設開機啓動的話工具
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist(取消開機啓動)
nginx命令
sudo nginx #打開 nginx
nginx -s reload|reopen|stop|quit #從新加載配置|重啓|中止|退出 nginx
nginx -t #測試配置是否有語法錯誤
若是提示pid丟失的話,就用這句話
nginx -c "/usr/local/etc/nginx/nginx.conf"
好了nginx安裝完畢,你們能夠localhost一下,就能夠看到nginx的信息了
3.安裝MYSQL
brew install mysql
加入開機啓動
cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist(取消開機啓動)
初始化mysql
cd /usr/local/Cellar/mysql/5.7.18_1/bin
mysql_install_db
設置root帳戶和密碼
./mysql_secure_installation 一直跟着提示走就行
4.先安裝php7
brew install php70 --without-apache --with-fpm
由於咱們用nginx,全部--without-apache,而且加上--with-fpm來編譯php
安裝完成加入全局配置環境
vim ~/.bash_profile 添加 export PATH=/usr/local/bin:/usr/sbin:$PATH
而後 vim ~/.bashrc 添加 export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"
最後 sourc ~/.bash_profile
source ~/.bashrc
加入開機自啓動
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
5.安裝php5.6.30
brew install php56 --without-apache --with-fpm
vim ~/.bashrc 修改[PATH後面的等號不能留空格]
export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH" 爲
export PATH="$(brew --prefix homebrew/php/php70)/bin:$(brew --prefix homebrew/php/php56)/bin$PATH";
加入開機自啓 mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php70/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
6.安裝php切換工具
brew install php-version
執行加入到環境變量 source $(brew --prefix php-version)/php-version.sh
echo "source $(brew --prefix php-version)/php-version.sh" >> ~/.bash_profile
命令行添加 vim ~/.bashrc 添加 source $(brew --prefix php-version)/php-version.sh && php-version 7.0.20 (後面的是默認開啓的php版本; )
執行 source ~/.bashrc 後,執行
source $(brew --prefix php-version)/php-version.sh && php-version 7.0.20
php-version 能夠隨意切換
7.安裝php擴展庫
先查看對應的php版本有哪些擴展 brew search php70 ;
而後 brew install XXX 安裝便可;
8.配置Nginx和php-fpm
nginx 配置 很簡單,nginx的配置文件在 /usr/local/etc/nginx/文件中 vim nginx.conf
而後 根據 本身的需求去配置就行,這裏就不用詳細說了
php-fpm的配置: 先cd到 /usr/local/etc/php,你能夠看到7.0和5.6這倆個文件夾,至於你想要改哪一個,就改就行
9.重啓Nginx和php-fpm
sudo killall php-fpm 先停掉全部php-fpm的進程
cd /usr/local/Cellar/php/版本號/sbin
不一樣版本的php,sbin目錄裏會有不一樣的php-fpm,好比php7.0的是php70-fpm, php5.6.18的是 php56-fpm,你想啓動哪一個fpm就
sudo ./php70-fpm start 或php56-fpm start就行