Mac 搭建 LNMP 环境
1.安装 nginx
#安装
$ brew install nginx
# 默认是监听8080端口,更改监听80端口的话,需改修改权限,并设置为开机自启
$ sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/
$ sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
# 启动 关闭 操作
$ sudo nginx
$ sudo nginx -s reload|reopen|quit # 重新加载|重启|退出
或
$ brew services start/stop/reload/restart nginx
# 测试是否成功
$ curl -Il http://127.0.0.1:8080
# 结果显示:
HTTP/1.1 200 OK
Server: nginx/1.21.3
Date: Sun, 31 Oct 2021 14:15:21 GMT
Content-Type: text/html
Content-Length: 601
Last-Modified: Sun, 31 Oct 2021 13:33:00 GMT
Connection: keep-alive
ETag: "617e9b0c-259"
Accept-Ranges: bytes
# /usr/local/etc/nginx/nginx.conf 配置文件
listen 80;
....
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
2.安装php7.4
# 安装,安装到 /usr/local/etc/php/7.4
$ brew install php@7.4
# 然后根据提示,执行
echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc
# 设置开启自启
$ mkdir -p ~/Library/LaunchAgents
$ cp /usr/local/opt/php@7.4/homebrew.mxcl.php@7.4.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php@7.4.plist
# 查看php-fpm 是否运行
$ lsof -Pni4 | grep LISTEN | grep php
# 启动
$ brew services start php@7.4
3.安装mysql
# 安装
$ brew install mysql@5.7
# 设置MySQL的开机自启动
$ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
4. 安装 redis
# 安装
$ brew install redis
# 方式一:使用brew帮助我们启动软件
$ brew services start redis
# 方式二
$ redis-server /usr/local/etc/redis.conf
# 执行以下命令
$ redis-server
# 查看redis服务进程
$ ps aux | grep redis
# redis-cli连接redis服务
$ redis-cli -h 127.0.0.1 -p 6379
# 关闭redis服务
$ redis-cli shutdown
# 强行终止redis
$ sudo pkill redis-server
# 谁开机自启
$ cp /usr/local/Cellar/redis/6.2.6/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/
4.1.1 安装php-redis扩展
# 从官网下载redis扩展包 redis-5.3.4.tgz
$ tar -zxvf redis-5.3.4.tgz
$ cd redis-5.3.4
$ phpize
$ ./configure --with-php-config= /usr/local/Cellar/php@7.4/7.4.25/bin/php-config
$ make && make install
#然后在php.ini文件中加入 extension = "redis.so",重启php即可
5.安装PHP5.6
因为homebrew PHP5.6已经被废弃了,所以想要使用其安装php5.6 需要
$ brew tap shivammathur/php
$ brew tap`可以为`brew`的软件的 跟踪,更新,安装添加更多的的`tap formulae
如果你在核心仓库没有找到你需要的软件,那么你就需要安装第三方的仓库去安装你需要的软件
tap
命令的仓库源默认来至于Github
,但是这个命令也不限制于这一个地方
$ brew instll brew tap shivammathur/php/php@5.6
步骤通上面安装7.4