mac lnmp 安装mysql_Mac使用brew搭建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

brew services start|stop|restart nginx|mysql@5.7|php72

二、安装PHP7.2 Nginx MySQL5.7

安装PHP7.2

执行命令brew install php72,出现下图即为安装成功;

若安装失败,可能是因为之前使用brew安装过,没有删除干净,按照提示操作即可

0a0b2e3a1d7717770bd03c9ce99db55e.png

解释:

配置文件的安装位置最后都有提示,一般来说都是 /usr/local/etc/php/7.2/;

需要按照提示添加环境变量;

1、查看是否安装成功

lsof -Pni4 | grep LISTEN | grep php

出现下图即为安装成功

8a409c786388b66398e7ad3b63c87c57.png

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/*;,如下图所示

e9a987f0af999e84b264aad572ec31d0.png

若没有,请在 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');

453e9459f75f0a30d934b10e0f2c2e7e.png

三、测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值