## 安装brew
```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
```
> 来自:https://brew.sh/index_zh-cn
> 安装好的目录:`/usr/local/Homebrew/`
## 安装 MySql
```brew
brew search mysql
```
搜索一下,看看有什么版本,大家可以根据自己的需要选择版本,我这选择 5.7
```brew
brew install mysql@5.7
```
静静等待安装,安装完成之后启动服务:立即启动mysql@5.7并在登录时重新启动
```brew
brew services start mysql@5.7
```
或者:
```brew
mysql.server start
```
根据安装完之后的信息提示,我们需要设置root账户密码
```
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
```
执行
```
mysql_secure_installation
```
按照信息提示一步一步完成。然后记得把 mysql 添加到环境变量中去
在 `~/.zshrc` 中添加
```
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
```
后面是自己 mysql 的安装目录
执行一下命令使其生效
```
source ~/.zshrc
```
因为我用的是 zsh,所以是在 .zshrc ,如果你是使用默认的 bash,那同样在 ~/.bash_profile 添加环境变零,使其生效即可
``
root xxxxxx
``
## 安装 Nginx
```
brew install nginx
```
等待安装完成,编辑 `/usr/local/etc/nginx/nginx.conf`配置文件,将默认监听的端口 8080 改成 80
```nginx
http {
............
server {
listen 80;
server_name localhost;
#charset koi8-r;
.......
```
启动服务
```
brew services start nginx
```
访问 http://localhost ,就可以看到 Nginx 的欢迎页面了
## 安装 PHP
### php5.6
添加源
```
brew tap exolnet/homebrew-deprecated
```
搜索PHP
```
brew search php
```
安装PHP
```
brew install php@5.6
```
```
### 使用自带的 bash
echo 'export PATH="/usr/local/opt/php@5.6/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@5.6/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
### 使用 zsh
echo 'export PATH="/usr/local/opt/php@5.6/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@5.6/sbin:$PATH"' >> ~/.zshrc
source ~/.zshrc
```
> 因为需要与其他Php版本共存,所以我们需要修改php-fpm的监听端口)
brew安装的软件目录一般在/usr/local/Cellar,配置文件一般在/usr/local/etc
进入/usr/local/etc/php/5.6/
修改php-fpm.conf
listen = 127.0.0.1:9001
启动php5.6
```
brew services start php@5.6
```
### php7.4
首先执行,清除php56的软链,此操作对软件本身毫无影响,**未安装php5.6忽略**
```
brew unlink php@5.6
```
同样使用
```
brew search php
```
找你所需要的版本安装
```
brew install php
```
这样,它会直接安装最新版本的 php。查看 php 版本发现还是系统自带的 7.1 版本,这个是因为还没把我们安装的最新版本加到环境变量中去。
```
### 使用自带的 bash
echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
### 使用 zsh
echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.zshrc
### for other brew install soft
echo 'export PATH="/usr/local/bin:/usr/local/sbib:$PATH"' >> ~/.zshrc
source ~/.zshrc
```
启动php
```
brew services start php@7.3
```
重启php
```
brew services restart php@7.3
```
## 配置 PHP 和 Nginx
`/usr/local/etc/nginx/servers` 目录下添加 `default.conf`
```nginx
server {
listen 80;
server_name default.me ; ## 根据自己需要填写
root "/usr/local/var/www/default"; ## 根据自己的目录
index index.html index.htm index.php;
location / {
#autoindex on;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
```
再次检查 `/usr/local/etc/nginx` 目录下是否存在 `fastcgi.conf` ,`nginx.conf`
如果没有的话,复制默认的
```
cp nginx.conf.default nginx.conf
cp fastcgi.conf.default fastcgi.conf
```
重启服务
```
_ php-fpm -d
nginx -s reload
```
就可以开心的玩耍了。
————————————————
原文作者:Zhengkx
转自链接:https://learnku.com/articles/35927
版权声明:著作权归作者所有。商业转载请联系作者获得授权,非商业转载请保留以上作者信息和原文链接。
完全卸载brew并删除所有包
```
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
```
brew安装nmp环境