本篇文章是通过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. Xcode修改工程文件名字

    http://stackoverflow.com/questions/8262613/renaming-xcode-4-project-and-the-actual-folder

  2. 微信跳转外部浏览器下载app原理

    在我们使用微信营销的时候,很容易碰到推广连接在微信内无法打开或无法下载app的情况.通常这种情况微信会给个提示 “已停止访问该网址” ,那么导致这个情况的因素有哪些呢,主要有以下三点 1.网页链接被举 ...

  3. 【JavaWeb】JSTL标签库

    JSTL标签库 JSTL标准标签库: JSTL用于简化JSP开发,提高代码的可读性与可维护性: JSTL由SUN(Oracle)定义规范,由Apache Tomcat团队实现: 引用JSTL核心库 核 ...

  4. Linux根目录下各目录含义

    /boot:系统启动的相关文件,比如内核,grub /etc:配置文件 /dev:设备文件 /root:root用户的家目录 /home:用户家目录 /lib:库文件 /bin:用户的命令文件 /sb ...

  5. 【mysql】pymysql.err.InterfaceError Interface Error: (0, '')

    八成是丢失连接了 while 1: try: self.conn.ping(reconnect=True) self.cur.execute(sql,tuple(item.values())) sel ...

  6. 在C++工程上添加CUDA编译环境

    1.直接在新建工程的时候选择CUDA,这样的工程既能编译C++也能编译CU 2.在已有的C++工程上添加CUDA编译环境 右键工程-->生成依赖项-->生成自定义-->勾选CUDA ...

  7. matplotlib画3D图修改X,Y,Z,colorbar的刻度值

    修改X,Y,Z轴的刻度值 from matplotlib.ticker import MultipleLocator,FuncFormatter from mpl_toolkits.mplot3d i ...

  8. python copy和deepcopy

    Python FAQ2:赋值.浅拷贝.深拷贝的区别? 发表于 2014-08-15   |   分类于 Lang.-Python  |   在写Python过程中,经常会遇到对象的拷贝,如果不理解浅拷 ...

  9. NOIP2007 奖学金 结构体排序

    是结构体排序的练习题,可供选手们巩固结构体排序的一些相关内容. 关于结构体排序 1.结构体定义 struct student { int num,a,b,c,sum; }p[]; 2.结构体初始化 ; ...

  10. 安装QTP之后造成环境变量java冲突问题的解决方案

    参考:http://www.cnblogs.com/yhcreak/p/6340125.html