Bootstrap

Mac环境下brew安装LNMP

安装不同版本PHP

在Mac环境下同时运行多个版本的PHP,同Linux环境一样,都是将后台运行的php-fpm设置为不同的端口号,下面将已[email protected] 和 php@@7.4为例

添加 tap

目的:homebrew仅保留最近的php版本,可能没有你需要的版本,推荐使用shivammathur进行安装。安装完成后即可使用brew search php查找到更多历史版本的PHP。

# 为brew添加tap工具
brew tap shivammathur/php

安装[email protected][email protected]

安装过程不在累述

# 安装[email protected]
brew search [email protected]

brew install [email protected]

# 安装[email protected]
brew search [email protected]

brew install [email protected]

配置[email protected][email protected]

分别进入[email protected][email protected]的php-fpm配置目录,修改user、group、listen、listen.owner、listen.group,配置推出并分别重启[email protected] & [email protected]

  1. user:执行php-pmf的用户,建议与nginx执行用户保持一致,否则会遇到执行权限问题
  2. group:执行php-pmf的用户组,建议与nginx执行用户保持一致,否则会遇到执行权限问题
  3. listen:php-pmf的端口号,接受FastCGI请求的地址。[email protected][email protected]端口号一定不要相同;
    1. 例如[email protected] listen 设置为 9002;
    2. 例如[email protected] listen 设置为 9004;
  4. listen.owner:设置unix套接字的权限,即允许设置的用户进行监听,默认所有用户均可监听。必须设置权限才能允许来自web服务器的连接。
  5. listen.group:设置unix套接字的权限,即允许设置的用户进行监听,默认所有用户均可监听。必须设置权限才能允许来自web服务器的连接。

配置Nginx 与 PHP(php-fpm)

首先启动[email protected][email protected],已知配置[email protected]端口号是9002,[email protected]端口号是9004,Nginx转发地址地址分别是`fastcgi_pass   127.0.0.1:9004;`和`fastcgi_pass   127.0.0.1:9004;`。nginx配置完成并重启Nginx

配置Nginx & [email protected] 通讯(TCP模式)如下

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

命令行配置(别名方式)

1、编辑用户级配置文件`~/.zshrc`,添加内容如下:

# php
alias php72='/opt/homebrew/opt/[email protected]/bin/php'
alias php74='/opt/homebrew/opt/[email protected]/bin/php'

2、刷新终端窗口或重新打开窗口php72、php74命令生效

ling@userdeMacBook-Pro homebrew % vim ~/.zshrc   

ling@userdeMacBook-Pro homebrew % source ~/.zshrc

ling@userdeMacBook-Pro homebrew % php72 -v
PHP 7.2.34 (cli) (built: Sep 27 2024 12:55:57) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.34, Copyright (c) 1999-2018, by Zend Technologies

ling@userdeMacBook-Pro homebrew % php74 -v
PHP 7.4.33 (cli) (built: Nov 22 2024 10:43:27) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

ThinkPHP Nginx 重写配置​​​​​​​

;