Contents

本文是brew 安装,没有安装brew的先去安装brew

1
2
3
4
5
6
先搞定brew
安装homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/maste
r/install)"

brew update && brew upgrade

nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
	
安装nginx
brew install nginx

修改配置文件
sudo vim /usr/local/etc/nginx/nginx.conf
#修改默认的8080端口为80

给予管理员权限
Nginx监听80端口需要root权限执行,因此:
sudo chown root:wheel /usr/local/Cellar/nginx/1.15.8/bin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.15.8/bin/nginx

加入launchctl启动控制
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

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

mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
安装mysql
brew install mysql

mkdir -p ~/Library/LaunchAgents/
cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
#取消启动
#launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

执行安全设置脚本,设置root账号密码
cd /usr/local/Cellar/mysql/8.0.13/bin/
./bin/mysql_secure_installation

命令行连接mysql

mysql -uroot -p

php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Mac OS 内置了Apache 和 PHP,查看一下版本号。 我有洁癖,要把他们删除干净


httpd -v
php --version

接下来删除

sudo apachectl stop #关闭apache,如果事先没开启过,可以忽略报错信息
如果你的apache已经加入了launchctl,使用下面的命令来关闭:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
为什么选择关闭apache?因为mac os x系统自带的apache是没有优雅的remove/uninstall 的方式的... 对于“洁癖”比较严重的童鞋,可以选择直接删除相关的文件!(千万不要手抖删错目录...)

sudo rm /usr/sbin/apachectl
sudo rm /usr/sbin/httpd
sudo rm -r /etc/apache2/
删除自带的php

sudo rm -r /usr/bin/php

开始安装php
brew install php

将php路径加入PATH
sudo vim ~/.bash_profile
export PATH="$(brew --prefix php54)/bin:$PATH"
source ~/.bash_profile

加入launchctl启动控制
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/php/7.3.1/homebrew.mxcl.php.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php.plist
配置路径

/usr/local/etc/php/7.3/php.ini
/usr/local/etc/php/7.3/php-fpm.conf

这儿记得修改php.ini
将;pcre.jit=1
改为:pcre.jit=0

重启php launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php.plist

配置 Nginx 支持 PHP-FPM

sudo vim /usr/local/etc/nginx/nginx.conf

# 添加默认首页 php
index index.php index.html index.htm;

# 取消以下内容的注释,并做修改
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/Cellar/nginx/1.15.8/html$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}

重启nginx
编写测试php文件测试是否能编译php代码

composer安装参照我之前的博文http://www.iwangsen.com/2018/09/03/use-yum-list/

Contents