mac 首先要安装homebrew,以下的安装步骤都是基于homebrew的
一.安装PHP
#查找php
brew search php
#安装指定版本php
brew install php@7.3
#安装完成后 把php 和php-fpm 加入环境变量,由于我使用的是zsh,所以是下面的,默认是bash_profile文件,你也可以把环境变量配置在 ~/.bash_profile 里面
echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.zshrc
# 启动php73
brew services start php@7.3 或者 php-fpm
二.安装nginx
brew install nginx
#安装完成,默认项目目录
/usr/local/var/www
#nginx配置目录
/usr/local/etc/nginx/nginx.conf
# nginx配置虚拟域名文件夹
/usr/local/etc/nginx/servers/
#nginx 启动
brew services restart nginx 或者 nginx
#安装完成启动nginx
浏览器中键入http://localhost:8080,即可访问到nginx的欢迎界面
#重启nginx
nginx -s reload
#测试是否有语法错误
nginx -t
三.安装mysql
#查找mysql
brew search mysql
#安装指定版本mysql
brew install mysql@5.7
#安装完成后把mysql配置到环境变量
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
#启动mysql
brew services start mysql@5.7 或者 /usr/local/opt/mysql@5.7/bin/mysql.server start
四.nginx虚拟域名配置
范例:
server {
listen 8080;
server_name dev.test.com; #本地域名,可以在host里定义
root /usr/local/var/www; #项目文件地址
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
try_files $uri /index.php =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}