当前位置: 首页 > news >正文

mac m2芯片 安装nginx + php + mysql

1.安装homebrew:

系统本身就有(命令brew -v查看下),如果没有安装一下

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

2.安装nginx

brew install nginx

3.安装php

brew tap shivammathur/php
brew search php
brew install shivammathur/php/php@7.4

如果安装多个php版本,就修改下PHP端口配置:

我的路径是:/opt/homebrew/etc/php/7.4/php-fpm.d/www.conf

listen = 127.0.0.1:9000
改为
listen = 127.0.0.1:9074

4.修改nginx配置

sudo vim /opt/homebrew/etc/nginx/nginx.conf

#user  nobody;
worker_processes  1;error_log  /var/logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;include servers/*;
}

5.在 /opt/homebrew/etc/nginx下新建文件夹servers,在servers下新建新建test1.conf和test2.conf

mkdir servers
cd servers    
vim test1.conf

test1.conf配置内容

server {listen       80;server_name www.test1.cn;# 配置项目路径root  /Users/liuxiaoyun/www/test1; #access_log  logs/host.access.log  main;location / {index  index.html index.htm index.php;if (!-e $request_filename) {rewrite  ^(.*)$  /index.php?s=/$1  last;break;}}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000location ~ \.php$ {# 9074上面设置的监听端口,加载php7.4fastcgi_pass   127.0.0.1:9074;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;include        fastcgi_params;}
}

test2.conf的配置

server {listen       80;server_name www.test2.cn;# 配置项目路径root  /Users/liuxiaoyun/www/test2; #access_log  logs/host.access.log  main;location / {index  index.html index.htm index.php;if (!-e $request_filename) {rewrite  ^(.*)$  /index.php?s=/$1  last;break;}}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000location ~ \.php$ {# 9074上面设置的监听端口,加载php7.4fastcgi_pass   127.0.0.1:9074;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;include        fastcgi_params;}
}

6.检查配置

nginx -t
如果报文件权限问题:sudo chmod -R 777 /var/logs

7.设置php-fpm开机自启

sudo cp /opt/homebrew/opt/php@7.4/homebrew.php@7.4.service /Library/LaunchAgents

8.启动php-fpm

brew services start php@7.4

9.验证是否启动成功

lsof -i :9074

10.终端切换php版本

解除之前版本链接:brew unlink php
增加新版本链接:
brew link --overwrite php@7.4

11.php加入环境变量

echo 'export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc

12.安装composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer74

13.验证composer

composer74 -v

14.mysql加入环境变量

 echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrcFor compilers to find mysql@5.7 you may need to set:export LDFLAGS="-L/opt/homebrew/opt/mysql@5.7/lib"export CPPFLAGS="-I/opt/homebrew/opt/mysql@5.7/include"

15.启动数据库

 brew services start mysql@5.7

16.brew安装mysql5.7总是出问题,我的解决办法是,更新homebrew,安装的mysql8.0

17.php项目运行:

(1).nginx执行重新加载:nginx -s reload ;报错:

[error] invalid PID number "" in "/opt/homebrew/var/run/nginx.pid"

解决:

重新加载配置文件 nginx.conf,然后再执行 reload:nginx -c /opt/homebrew/etc/nginx/nginx.conf
nginx -s reload 

(2). 修改hosts文件,/etc/hosts。添加自定义本地域名

#上边配置的test1.conf和test2.conf文件里自定义的域名
127.0.0.1。www.test1.cn
127.0.0.1。www.test2.cn

(3).在~/www/test1里添加index.php。访问域名www.test1.cn就完成啦

http://www.lryc.cn/news/259294.html

相关文章:

  • vue axios 使用
  • 使用docker实现logstash同步mysql到es
  • hive数据仓库工具
  • C语言 联合体验证 主机字节序 +枚举
  • python和pygame实现烟花特效
  • gRPC-Gateway:高效转换 RESTful 接口 | 开源日报 No.105
  • 非专业的建模人员如何给模型设置材质纹理贴图?
  • 自动化测试、压力测试、持续集成
  • FFmpeg之HWContextType
  • Python面向对象之类和对象(Python系列16)
  • 电商对传统零售业的影响:销售渠道、价格竞争与服务质量挑战
  • DENet:用于可见水印去除的Disentangled Embedding网络笔记
  • C++初阶(十五)Stack和Queue
  • C#面试题
  • python源码,在线读取传奇列表,并解析为需要的JSON格式
  • 二叉排序树的判断(二叉树的顺序存储):2022年408算法题
  • Kubernetes版本升级到v1.18.0方法
  • 了解 git rebase
  • 程序员的养生之道:延寿健康的十大秘诀(下)
  • 【java】保留前N月数据文件,定期删除数据
  • 12.9_黑马数据结构与算法笔记Java
  • K8S学习指南(1)-docker的安装
  • vue3 + mark.js 实现文字标注功能
  • 运筹优化 | 模拟退火求解旅行商问题 | Python实现
  • 1017 A除以B
  • SAP UI5 walkthrough step8 Translatable Texts
  • RocketMQ-源码架构二
  • Unity_ET框架项目-斗地主_启动运行流程
  • 自动化测试框架 —— pytest框架入门篇
  • String类详解