mac 安装LNMP环境
一. 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
二.安装PHP7.2
1.安装PHP7.2
brew install php72
安装后文件路径 /usr/local/etc/php/7.2/ 也是php.ini的路径
/usr/local/opt/[email protected]/bin php和phpize 和php-config路径
brew uninstall [email protected] 卸载php72
2.查看是否安装成功
lsof -Pni4 | grep LISTEN | grep php
出现下图即为安装成功
3.将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
4..将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
如果你使用的是zshrc
vi ~/.zshrc
同样配置上面信息
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 ~/.zshrc
5.安装php扩展
实例:安装zip扩展
brew install php72 zip
6. 重启PHP
brew services restart php72
启动
brew services start php72
三.安装nginx
brew install nginx
nginx文件默认安装在/usr/local/etc/nginx 默认端口8080
浏览器中键入http://localhost:8080,即可访问到nginx的欢迎界面
1.使用 vim /usr/local/etc/nginx/nginx.conf,查看是否有 include services/*;,如下图所示
若没有,请在 vim /usr/local/etc/nginx/ 目录新建一个 services 文件夹,并在nginx.confd对应位置(一般是倒数第二行)中添加 include services/*;
网站默认根目录 /usr/local/var/www
配置虚拟域名
在/usr/local/etc/nginx/servers下建立default.conf 文件名可以任意起名
vi default.conf
内容如下:
server {
listen 8080;
server_name dev.test.com; #本地域名,可以在host里定义
root /usr/local/var/www; #项目文件地址
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
try_files $uri /index.php =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
保存,退出,重启nginx
nginx -s reload
2.常用命令
nginx -t 测试是否有语法错误
重新加载配置|重启|停止|退出 nginx
nginx -s reload|reopen|stop|quit
启动nginx sudo brew services start nginx
sudo nginx
Nginx开机启动,不过推荐自己启动
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
四. 安装Mysql5.7
1.安装mysql
brew install [email protected]
2.设置MySQL的开机自启动
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/[email protected]
3.配置mysql到path 环境变量
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
4.启动重启
brew services start [email protected] 启动mysql
brew services restart [email protected] 重启mysql
/usr/local/opt/[email protected]/bin/mysql.server start 这样也可以启动
5.设置root用户密码
设置MySQL的登录密码,由于刚刚安装的MySQL是没有配置密码的,直接回车即可进入,安全起见,需要设置下root的登录密码
set password for [email protected] = password('root');
报错这种的
zsh: command not found: mysql
vi ~/.zshrc
增加下面的一行即可 后面的路径是mysql 安装路径
alias mysql=/usr/local/opt/[email protected]/bin/mysql
如果使用的默认终端,则vi ~/.bash_profile 增加
alias mysql=/usr/local/opt/[email protected]/bin/mysql
然后执行修改的文件 source 文件名 如source ~/.zshrc