MAC下安装nginx,php

MAC下安装nginx,php

1.安装brew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2.查找nginx版本

brew search nginx

3.安装nginx

brew install nginx
#默认是最新版本
#指定版本安装方式为:nginx@版本号
brew install nginx@1.17.2

执行安装提示:

No such file or directory @ rb_sysopen - /Users/a1/Library/Caches/Homebrew/downloads/8c89df067f371d8b5549916dc03405f582183144d670b9f0905723a672212c0e--ca-certificates-2022-03-18.all.bottle.tar.gz

意思是,安装过程中,安装依赖的包出错了。
解决方式: brew install ca-certificates ,单独来安装这个包。
然后,再重新执行brew install nginx 即可

在这里插入图片描述

执行brew install nginx 出现权限问题:
sudo chown -R $(whoami) $(brew –prefix)/*
解决下面权限的问题

cp: /private/tmp/d20220531-76522-1gsbk7y/openssl@1.1/./1.1.1o/share: unable to copy ACL to /usr/local/Cellar/openssl@1.1/./1.1.1o/share: No such file or directory
cp: utimes: /usr/local/Cellar/openssl@1.1/./1.1.1o: No such file or directory
cp: chown: /usr/local/Cellar/openssl@1.1/./1.1.1o: No such file or directory
cp: chmod: /usr/local/Cellar/openssl@1.1/./1.1.1o: No such file or directory
cp: chflags: /usr/local/Cellar/openssl@1.1/./1.1.1o: No such file or directory
cp: /private/tmp/d20220531-76522-1gsbk7y/openssl@1.1/./1.1.1o: unable to copy ACL to /usr/local/Cellar/openssl@1.1/./1.1.1o: Permission denied
cp: utimes: /usr/local/Cellar/openssl@1.1/.: Operation not permitted

4.卸载nginx

brew uninstall nginx
brew uninstall nginx@版本号

卸载nginx 提示

 No such keg: /usr/local/Cellar/nginx

因为之前有安装过nginx,使用下面方法卸载

brew uninstall --force nginx

5.查看nginx安装信息

brew info nginx
#网页目录: /usr/local/var/www
#默认配置文件:/usr/local/etc/nginx/nginx.conf
#会被加载的配置文件: /usr/local/etc/nginx/servers/
nginx: stable 1.21.6 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/usr/local/Cellar/nginx/1.21.6_1 (26 files, 2.2MB) *
  Poured from bottle on 2022-05-31 at 14:35:02
From: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git/Formula/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@1.1, pcre2 ✔
==> Options
--HEAD
	Install HEAD version
==> Caveats
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /usr/local/etc/nginx/servers/.
To restart nginx after an upgrade:
  brew services restart nginx
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/nginx/bin/nginx -g daemon off;
==> Analytics
install: 25,508 (30 days), 101,358 (90 days), 459,756 (365 days)
install-on-request: 25,440 (30 days), 101,141 (90 days), 458,786 (365 days)
build-error: 11 (30 days)

6.查看已安装的软件

brew list

7.启动、停止、重启nginx(推荐)

brew services start nginx
brew services stop nginx
brew services restart nginx

8.nginx原生常用命令启动、停止、重新加载配置文件(不推荐)

nginx #启动nginx
nginx -s reload #重新加载配置文件 ,热加载配置文件
nginx -s quit #:推荐 待nginx进程处理任务完毕进行停止
nginx -s stop #:先查出nginx进程id再使用kill命令强制杀掉进程。

9.查询nginx进程:

ps aux|grep nginx
ps -ef|grep nginx

mkdir -p /usr/local/var/logs/nginx
vim /usr/local/etc/nginx/nginx.conf
把错误日志目录修改为:
error_log /usr/local/var/logs/nginx/error.log debug;

10. 安装PHP

brew search php	#搜索php
==> Formulae
brew-php-switcher  php-code-sniffer   php-cs-fixer@2     php@7.3            php@8.0            phplint            phpmyadmin         phpunit            pup
php                php-cs-fixer       php@7.2            php@7.4           phpbrew            phpmd            
phpstan            pcp
==> Casks
安装 
brew install php@7.4	#安装php7.4
#写入环境变量
echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc	#php
echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc	#php-fpm
#刷新配置文件
source ~/.zshrc
设置PHP-FPM 开机启动:
ln -sfv /usr/local/opt/php@7.4/*.plist ~/Library/LaunchAgents

11启动|停止|重启 PHP

brew services start|stop|restart php

启动php后,使用以下命令监测php-fpm是否启动成功,监听9000端口:

lsof -Pni4 | grep LISTEN | grep php

执行 sudo vim /etc/hosts
配置相对应访问域名
127.0.0.1 xxxxx.com

                       

点击阅读全文

上一篇 2023年 6月 15日 am10:38
下一篇 2023年 6月 15日 am10:39