【笔记】MacOS上部署PHP环境

前言

MacOS上部署PHP环境

Apache + PHP

下载依赖

1
brew install httpd php

修改Apache配置文件

  • 启用php模块
/opt/homebrew/etc/httpd/httpd.conf
1
2
LoadModule proxy_module lib/httpd/modules/mod_proxy.so
LoadModule proxy_fcgi_module lib/httpd/modules/mod_proxy_fcgi.so
  • .php文件交给CGI处理
/opt/homebrew/etc/httpd/httpd.conf
1
2
3
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
  • 添加index.php作为首页
/opt/homebrew/etc/httpd/httpd.conf
1
2
3
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>

重启服务

1
2
brew services restart php
brew services restart httpd

Nginx + PHP

下载依赖

1
brew install nginx php

修改Nginx配置文件

/opt/homebrew/etc/nginx/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

server {
listen 80;
listen [::]:80;
server_name _;
root html;
index index.php index.html index.htm;

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

重启服务

1
2
brew services restart php
brew services restart nginx

完成

参考文献

CSDN——赫赫phper
知乎——知乎用户