ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install nginx
修改配置文件php
sudo vim /usr/local/etc/nginx/nginx.conf #修改默認的8080端口爲80
給予管理員權限html
sudo chown root:wheel/usr/local/opt/nginx/bin/nginx sudo chmod u+s/usr/local/opt/nginx/bin/nginx
加入launchctl啓動控制mysql
mkdir -p ~/Library/LaunchAgents cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist~/Library/LaunchAgents/launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
運行nginxnginx
sudo nginx #打開 nginx nginx -s reload|reopen|stop|quit #從新加載配置|重啓|中止|退出 nginx nginx -t #測試配置是否有語法錯誤
測試配置nginx的時候,開啓nginx有錯誤。如圖:git
這致使我在切換URL的時候獲取不到後臺的數據,還一直報錯404.github
個人解決方案:sql
sudo nginx -c /usr/local/etc/nginx/nginx.confapache
而後重啓一下:sudo nginx -s reload 就能夠了vim
經常使用的nginx命令: nginx -t 開啓nginx服務 sudo nginx 查看nginx狀態 vi /usr/local/etc/nginx/nginx.conf 打開nginx.conf配置文件 sudo lsof -i:80 查看nginx進程
安裝mysql瀏覽器
brew install mysql cd /usr/local/opt/mysql/
修改配置文件
sudo vim my.cnf #若是出現沒法啓動mysql,rm my.cnf
加入launchctl啓動控制
mkdir -p ~/Library/LaunchAgents/ 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
./bin/mysql_install_db #實在運行不了就跳過這一步
執行安全設置腳本,設置root帳號密碼
./bin/mysql_secure_installation
命令行鏈接mysql
mysql -uroot -p
1.安裝php7
brew install php70 --without-apache --with-fpm #由於咱們用nginx,全部--without-apache,而且加上--with-fpm來編譯php
2.安裝完成後,加入全局變量
vim ~/.bash_profile 添加上:export PATH=/usr/local/bin:/usr/sbin:$PATH 而後 vim ~/.bashrc 添加上:export PATH = "$(brew --prefix homebrew/php/php70)/bin:$PATH" 最後執行 source ~/.bash_profile source ~/.bashrc
3.而後加入開機自啓
mkdir -p ~/Library/LaunchAgents cp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
4.安裝php擴展
其實很簡單,好比你想安裝php7的xdebug擴展,就brew install php70-xdebug,想安裝mcrypt就 brew install php70-mcrypt 若是想按5.6的就 brew install php56-xxxx,是不so easy,另外你能夠 brew search php70,能夠看到全部php7的擴展庫,同理也能夠查php56的
5.配置 Nginx 支持 PHP-FPM
sudo vim /usr/local/etc/nginx/nginx.conf # 添加默認首頁 index.php index index.php index.html index.htm; # 取消如下內容的註釋,並作修改 location ~ \.php$ { fastcgi_intercept_errors on; fastcgi_pass 127.0.0.1:9000; #這裏根據你的php-fpm端口號而定 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /usr/local/etc/nginx/fastcgi_params; }
6.php-fpm配置:
sudo killall php-fpm #停掉全部php-fpm的進程
7.啓動php-fpm。不一樣版本的php,sbin目錄裏會有不一樣的php-fpm,好比php7.0的是php70-fpm, php5.6.18的是 php56-fpm,你想啓動哪一個fpm就敲
sudo ./php70-fpm start 或 sudo php56-fpm start 就行
個人php-fpm在cd /usr/local/Cellar/php70/7.0.26_18/sbin/這裏,
我這裏須要執行:
cd /usr/local/Cellar/php70/7.0.26_18/sbin/ sudo ./php70-fpm start
就能夠啓動php-fpm了。
測試環境 sudo vim /usr/local/Cellar/nginx/1.6.0_1/html/index.php #添加測試代碼 <?php echo phpinfo();
瀏覽器訪問http://localhost/index.php便可,執行成功,則表示環境搭建成功
Mac的hosts文件位置(配置域名使用)
cd /private/etc vim hosts