一、 brew
常用命令
安裝brew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
更新brew brew update
搜索mysql可用版本 brew search mysql
刪除php56 brew unlink php56
brew services start|stop|restart nginx|mysql@5.7|php72
二、安裝PHP7.2
Nginx
MySQL5.7
安裝PHP7.2
執行命令brew install php72
,出現下圖即為安裝成功;
若安裝失敗,可能是因為之前使用brew安裝過,沒有刪除干凈,按照提示操作即可
解釋:
配置文件的安裝位置最后都有提示,一般來說都是 /usr/local/etc/php/7.2/
;
需要按照提示添加環境變量;
1、查看是否安裝成功
lsof -Pni4 | grep LISTEN | grep php
出現下圖即為安裝成功
2、將PHP7添加到開機自啟中
mkdir -p ~/Library/LaunchAgents ln -sfv /usr/local/opt/php72/homebrew.mxcl.php72.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php72.plist
3、將php加入$PATH
vim ~/.bash_profile
添加如下配置文件
export PATH="/usr/local/sbin:$PATH"
export PATH="$(brew --prefix php72)/bin:$PATH"
export PATH="$(brew --prefix php72)/sbin:$PATH"
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
保存退出,運行配置
source ~/.bash_profile
4、安裝php7擴展
示例:安裝zip擴展
brew install php72 zip
5、重啟PHP
brew services restart php72
安裝Nginx
執行命令brew install nginx
,安裝完成后,nginx文件默認被安裝在/usr/local/etc/nginx/nginx.conf
,然后再瀏覽器中鍵入http://localhost:8080,即可訪問到nginx的歡迎界面。
1、配置文件
使用 vim /usr/local/etc/nginx/nginx.conf
,查看是否有 include services/*;
,如下圖所示
若沒有,請在 vim /usr/local/etc/nginx/
目錄新建一個 services
文件夾,並在nginx.confd對應位置(一般是倒數第二行)中添加 include services/*;
開始配置多站點
vim /usr/local/etc/nginx/services/default
在 default
中添加如下內容
server {
listen 80;
root /Users/yulong/Web/www/; #項目文件地址
index index.php index.html index.htm;
server_name www.test.loc; #本地域名,可以在host里定義
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
保存退出,重啟Nginx使配置生效
nginx -s reload
2、常用命令
測試配置是否有語法錯誤
nginx -t
重新加載配置|重啟|停止|退出 nginx
nginx -s reload|reopen|stop|quit
安裝MySQL5.7
執行命令安裝MySQL5.7 brew install mysql@5.7
1、設置MySQL的登錄密碼,由於剛剛安裝的MySQL是沒有配置密碼的,直接回車即可進入,安全起見,需要設置下root的登錄密碼
set password for root@localhost = password('root');
三、測試
參考文章:https://blog.csdn.net/weixin_42894969/article/details/89070153