本篇文章是通过homebrew安装,home brew对于Mac相当于centos 的yum一样方便简单,大家可以先去安装home brew。网上很多简单靠谱的例子,这里不写了

一、准备条件
为了安装最新的配置,我们提前升级brew

brew update

二、安装PHP7
1、安装php7.2

brew install php72

如果你的系统已经安装其他版本,报错可能如下

➜  ~ brew install php72

==> Installing php72 from homebrew/php
Error: Cannot install homebrew/php/php72 because conflicting formulae are installed.
php55: because different php versions install the same binaries.
Please `brew unlink php55` before continuing. //也就是你的系统已经安装php5.5
Unlinking removes a formula's symlinks from /usr/local. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side-effects in the
resulting software.

那么你可以卸载当前系统下的php5.5版本

brew unlink php55

然后继续安装

2、配置文件位置
好安装后生成的配置文件都在/usr/local/etc/php/7.2目录里,分别如下:
php.ini位置为/usr/local/etc/php/7.2/php.ini
php-fpm.conf位置为/usr/local/etc/php/7.2/php-fpm.conf
PHP运行phpize,PHP-配置ls /usr/local/opt/php72/bin
PHP-FPM位置为/usr/local/opt/php72/sbin/php-fpm

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

6、查看是否安装成功

lsof -Pni4 | grep LISTEN | grep php
//结果,表示安装成功了
php-fpm wangteng 8u IPv4 0xab953b14ed200d5d 0t0 TCP 127.0.0.1: (LISTEN)
php-fpm wangteng 9u IPv4 0xab953b14ed200d5d 0t0 TCP 127.0.0.1: (LISTEN)
php-fpm wangteng 9u IPv4 0xab953b14ed200d5d 0t0 TCP 127.0.0.1: (LISTEN)
phpstorm wangteng 176u IPv4 0xab953b14c83636dd 0t0 TCP 127.0.0.1: (LISTEN)
phpstorm wangteng 351u IPv4 0xab953b14fa71ca5d 0t0 TCP 127.0.0.1: (LISTEN)

7、重启php7
如果我们修改配置,需要重启一下php7

brew services restart php72

三、安装Nginx

1、安装

brew install nginx

通过homebrew,nginx文件默认被安装在/usr/local/etc/nginx/nginx.conf,然后再浏览器中键入http://localhost:8080,即可访问到nginx的欢迎界面。

2、配置
配置文件地址

vim /usr/local/etc/nginx/nginx.conf
nginx安装完访问本地默认的目录是    /usr/local/Cellar/nginx/1.15./html

在nginx的配置文件最下面有一个引入所有的一行代码,可以在这个目录下(server)创建不同的站点。

添加如下代码,每个意义看备注,多站点直接复制如下代码重新粘贴,然后修改root,server_name重启nginx即可

server {
listen ;
root /usr/local/etc/nginx/www/cat/public; #项目文件地址
index index.php index.html index.htm;
server_name web.cat.com; #本地域名,可以在host里定义
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}

配置完成我们可以重启nginx,让配置生效:

nginx -s reload

3、Nginx命令:

//测试配置是否有语法错误
nginx -t
//重新加载配置|重启|停止|退出 nginx
nginx -s reload|reopen|stop|quit

也可以使用Mac的launchctl来启动|停止

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

Nginx开机启动,不过推荐自己启动

ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

四、安装MySQL

//直接安装
brew install mysql@5.7

设置MySQL的开机自启动:

ln -sfv /usr/local/opt/mysql@5.7/*.plist ~/Library/LaunchAgents
/Users/wangteng/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist -> /usr/local/opt/mysql@5.7/homebrew.mxcl.mysql@5.7.plist

增加环境变量

export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"

增加完环境变量别忘了使之生效

然后启动mysql

mysql.server start

测试数据库是否安装成功

mysql -u root -p  //因为没有设置密码,两次回车即可

查看网络监听

$ netstat -nat | grep LISTEN
tcp4 127.0.0.1. *.* LISTEN
tcp4 127.0.0.1. *.* LISTEN
tcp4 *. *.* LISTEN
tcp4 *. *.* LISTEN
tcp4 127.0.0.1. *.* LISTEN
tcp4 127.0.0.1. *.* LISTEN
tcp4 127.0.0.1. *.* LISTEN
tcp4 127.0.0.1. *.* LISTEN
tcp6 *. *.* LISTEN
tcp4 *. *.* LISTEN
tcp6 fe80::aede:48ff:. *.* LISTEN
tcp6 fe80::aede:48ff:. *.* LISTEN
tcp6 fe80::aede:48ff:. *.* LISTEN
tcp6 fe80::aede:48ff:. *.* LISTEN

mac下安装php7.2、mysql5.7、nginx环境的更多相关文章

  1. mac 下安装php7.1 memcache扩展

    1.下载memcache源代码文件 https://github.com/websupport-sk/pecl-memcache/archive/php7.zip 文件夹名为:pecl-memcach ...

  2. mac下安装和配置mysql5.7.9

    我安装的是5.7.9版本的sql 一开始在网上看到的都是其他版本的安装,弄得自己卸载了好几次 mysql就只有一个dmg主文件,安装这一个就好了. 5.7以后安装的mysql不再使用旧版的默认密码:r ...

  3. mac 下安装php7.1 redis

    1.下载phpredis源文件 https://nodeload.github.com/nicolasff/phpredis/zip/master 下载后解压 2.执行命令 phpize  执行后执行 ...

  4. Mac下安装OpenCV3.0和Anaconda和环境变量设置

    入手Mac几天了,想在Mac OS下玩玩OpenCV和keras,间歇捣鼓了两天,终于搞定zsh.OpenCV3.0以及Anaconda.OpenCV3.0刚发布不久,这方面的资料也不是很多,能够查到 ...

  5. Mac下安装与配置Go语言开发环境

    1.官网下载安装包(需FQ) https://storage.googleapis.com/golang/go1.7.darwin-amd64.pkg 2.配置Go环境变量GOPATH和GOBIN ( ...

  6. Mac下安装oh my zsh之后配置环境变量失效问题

    背景:在刚拿到mac 的时候,使用了默认的bash,由于工作需要在电脑上安装了maven,在~/.bash_profile 文件中添加了maven的配置如下 $ cat ~/.bash_profile ...

  7. 《OD大数据实战》mac下安装nginx+php

    一.mac安装nginx + php + php-fpm  或apache + php 1. Mac 下 Nginx.MySQL.PHP-FPM 的安装配置 2. Mac下安装LNMP(Nginx+P ...

  8. Mac 下 安装 Nginx

    ---恢复内容开始--- Mac 下 安装nginx 首先确定自己有安装homebrew 安装 nginx brew install nginx 启动nginx 1.15版本下 安装是 直接在ngin ...

  9. MAC下安装与配置MySQL

    MAC下安装与配置MySQL   MAC下安装与配置MySQL 一 下载MySQL 访问MySQL的官网http://www.mysql.com/downloads/ 然后在页面中会看到“MySQL ...

随机推荐

  1. JavaScript初探 三 (学习js数组)

    JavaScript初探 (三) JavaScript数组 定义 创建数组 var 数组名 = [元素0,元素1,元素2,--] ; var arr = ["Huawei",&qu ...

  2. Dynamics CRM使用元数据之一:查询实体的主字段(托管代码版本)

    关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复159或者20151013可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! Dynamics CRM是基于元 ...

  3. iOS10 新特性一

    链接:http://www.jianshu.com/p/0cc7aad638d9 1.Notification(通知) 自从Notification被引入之后,苹果就不断的更新优化,但这些更新优化只是 ...

  4. 4.智能快递柜(通信篇-SOCKET)

    1.智能快递柜(开篇) 2.智能快递柜(终端篇) 3.智能快递柜(通信篇-HTTP) 4.智能快递柜(通信篇-SOCKET) 5.智能快递柜(通信篇-Server程序) 6.智能快递柜(平台篇) 7. ...

  5. ubuntu 查看软件包中的内容 (已经安装)

    在 使用 apt 进行安装软件的时候,我们要经常判断,软件安装了什么和安装到什么地方.这时候 我们要使用 dpkg -L 命令来进行查看: 同样 在 fedora 上可以使用 rpm -ql iper ...

  6. 渗透测试学习 二十八、WAF绕过详解

    大纲: WAF防护原理讲解 目录扫描绕过WAF 手工注入绕过WAF sqlmap绕过WAF 编写salmap绕过WAF 过WAF一句话编写讲解 菜刀连接绕过WAF webshell上传绕过WAF 提权 ...

  7. Linux 的 netstat 命令

    转载 https://www.cnblogs.com/ct20150811/p/9432043.html 一般用  netstat -lnp |grep "程序名"

  8. awk常用命令

    1.统计TCP的连接数量,其中LISTEN多少个,ESTABLISHED多少个. [root@heiniao ~]# netstat -ant Active Internet connections ...

  9. PyCharm2019.3专业版激活

    1. 首先到官网下载Professional(专业版),链接地址: https://www.jetbrains.com/pycharm/download/ 具体安装方法这里就不赘述 2. 下载补丁je ...

  10. golang数据结构和算法之CircularBuffer环形缓冲队列

    慢慢练语法和思路, 想说的都在代码及注释里. CircularBuffer package CircularBuffer const arraySize = 10 type CircularBuffe ...