Mac配置nginx+php
# Mac配置nginx+php(brew安装nginx+php)
# 第一步:检查本地有没有PHP:输入php -v 命令
brew install php
brew services start php@7.4
brew services list #查看运行状态
sudo lsof -i -P -n | grep 9000 #查看端口有没有fpm开启,fpm默认端口是9000,联动nginx的fastcgi_pass
1
2
3
4
2
3
4
# 修改php-fpm.conf文件
找到这个文件:/opt/homebrew/etc/php/7.4/php-fpm.conf
把pid 前面的分号删除,pid = run/php-fpm.pid
把error_log前面的分号删除,error_log = log/php-fpm.log
# 重启brew services restart php@7.4
# 第二步:安装nginx
brew install nginx
brew services start nginx
brew services restart nginx
1
2
3
4
2
3
4
查看信息
brew info nginx
Docroot is: /opt/homebrew/var/www
The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /opt/homebrew/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:
/opt/homebrew/opt/nginx/bin/nginx -g daemon\ off\;
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
#nginx 程序所在目录 /opt/homebrew/opt/nginx/bin/nginx
/opt/homebrew/opt/nginx/bin/nginx -t # 检测语法,brew services restart nginx错误一样运行成功
sudo nginx #启动nginx服务
sudo nginx -s reload #重启nginx服务
sudo nginx -s stop #停止nginx服务
sudo nginx -t #检测配置文件中是否存在语法错误
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
nginx/server/csm.test.conf
官网laravel:https://laravel.com/docs/10.x/deployment
server {
listen 80;
listen [::]:80;
server_name csm.test;
root /Users/luxiaoqing/project/test/blog-study/server/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php index.html index.htm;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000; # fpm的端口
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
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
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
# 验证
进入目录:cd /usr/local/var/www/
创建文件:touch index.php
编辑文件:sudo vi index.php
输入:<?php phpinfo(); ?> 保存并退出
1
2
3
4
2
3
4
http://localhost/index.php 验证
上次更新: 2023/08/23, 15:41:19