装置
brew install php@7.4 nginx
配置环境变量
vim ~/.zshrc
# PHP
export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"
export PATH="/opt/homebrew/opt/php@7.4/sbin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/php@7.4/lib"
export CPPFLAGS="-I/opt/homebrew/opt/php@7.4/include"
配置完环境变量运行一下 source ~/.zshrc
如果放心错过什么提醒能够运行 brew info php@7.4
配置文件夹开启 git 治理
cd /opt/homebrew/etc/php/7.4
# 用 git 治理 php 配置, 不然容易搞乱
git init && git add .
git commit -m "feat: initial commit"
cd /opt/homebrew/etc/nginx
# 用 git 治理一下 nginx 配置, 不然容易搞乱
git init && git add .
git commit -m "feat: initial commit"
创立 index.php
vim /opt/homebrew/var/www/index.php
<?php
phpinfo();
批改 nginx 配置
vim /opt/homebrew/etc/nginx/nginx.conf
location / {
root html;
index index.html index.htm index.php;
}
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;
}
批改阐明
1、index 行增加 index.php
2、勾销 php 相干的正文, 把默认的 /scripts$fastcgi_script_name
批改为 $document_root$fastcgi_script_name
重启服务
brew services restart php@7.4
brew services restart nginx
拜访 http://localhost:8080/index.php 就能看到 phpinfo 信息页
php 扩大
能够用 pecl 装置扩大, 不必手动去 php.ini 中开启
pecl install xdebug
idea 配置 xdebug
文件夹地位
nginx 门路:/opt/homebrew/var/www
nginx 配置文件:/opt/homebrew/etc/nginx/nginx.conf
nginx 默认端口是 8080 (80 端口须要 sudo)
php 配置文件:/opt/homebrew/etc/php/7.4/
php-fpm 默认监听 9000 端口