Mac M1Pro 安装 PHP 开发环境

安装

brew install [email protected] nginx

配置环境变量

vim ~/.zshrc

# PHP
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
export PATH="/opt/homebrew/opt/[email protected]/sbin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"

配置完环境变量运行一下 source ~/.zshrc

如果担心错过什么提示可以运行 brew info [email protected]

配置管理

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"

重启服务

brew services restart [email protected]
brew services restart nginx

创建 index.php

vim /opt/homebrew/var/www/index.php

修改 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

文件夹位置

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 端口

你可能感兴趣的:(php)