mac php7 nginx mysql_mac下安装php7.2、mysql5.7、nginx环境

本篇文章是通过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 thisinstall, but the build may fail or cause obscure side-effects inthe

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 27683 wangteng 8u IPv4 0xab953b14ed200d5d 0t0 TCP 127.0.0.1:9000(LISTEN)

php-fpm 27686 wangteng 9u IPv4 0xab953b14ed200d5d 0t0 TCP 127.0.0.1:9000(LISTEN)

php-fpm 27687 wangteng 9u IPv4 0xab953b14ed200d5d 0t0 TCP 127.0.0.1:9000(LISTEN)

phpstorm99685 wangteng 176u IPv4 0xab953b14c83636dd 0t0 TCP 127.0.0.1:6942(LISTEN)

phpstorm99685 wangteng 351u IPv4 0xab953b14fa71ca5d 0t0 TCP 127.0.0.1:63342 (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.12/html

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

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

server {

listen80;

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 =404;

fastcgi_split_path_info^(.+\.php)(/.+)$;

fastcgi_pass127.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

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

tcp40 0 127.0.0.1.3306 *.*LISTEN

tcp40 0 127.0.0.1.9000 *.*LISTEN

tcp40 0 *.80 *.*LISTEN

tcp40 0 *.8080 *.*LISTEN

tcp40 0 127.0.0.1.63342 *.*LISTEN

tcp40 0 127.0.0.1.30100 *.*LISTEN

tcp40 0 127.0.0.1.55154 *.*LISTEN

tcp40 0 127.0.0.1.6942 *.*LISTEN

tcp60 0 *.49159 *.*LISTEN

tcp40 0 *.49159 *.*LISTEN

tcp60 0 fe80::aede:48ff:.49156 *.*LISTEN

tcp60 0 fe80::aede:48ff:.49155 *.*LISTEN

tcp60 0 fe80::aede:48ff:.49154 *.*LISTEN

tcp60 0 fe80::aede:48ff:.49153 *.* LISTEN

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值