MacOS 12.3.x安装MNMP环境

安装MNMP首先安装brew,安装brew请查看我的另外一篇关于安装brew的文章

一、安装PHP

1.brew search php 列出所有php版本,根据自己需求安装具体版本,如php@7.4
$ brew search php
w-php-switcher      php@7.2             phplint             pcp
php                 php@7.3             phpmd               pup
php-code-sniffer    php@7.4           phpmyadmin
php-cs-fixer        php@8.0             phpstan
php-cs-fixer@2      phpbrew             phpunit

开始安装

$ brew install php@7.4

首次安装会提示git 错误
解决办法如下,运行下面两条命令

git config --global --add safe.directory /us r/local/homebrew/Library/Taps/homebrew/homebrew-core
git config --global --add safe.directory /usr/local/opt/homebrew/Library/Taps/homebrew/homebrew-cask

再继续执行

brew install php@7.4

继续执行以下命令

$ echo 'export PATH="$(brew --prefix php@7.4)/bin:$PATH"' >> ~/.bash_profile
$ echo 'export PATH="$(brew --prefix php@7.4)/sbin:$PATH"' >> ~/.bash_profile
$ echo 'export PATH="/usr/local/bin:/usr/local/sbib:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile
2.查看php版本 php -v
$ php -v
PHP 7.4.32 (cli) (built: Sep 29 2022 11:04:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.32, Copyright (c), by Zend Technologies
3.采用pecl安装php对应扩展 peel version
$ peel version
PEAR Version: 1.10.13
PHP Version: 7.4.32
Zend Engine Version: 3.4.0
Running on: Darwin appledeiMac.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64 x86_64

安装前先查看php扩展 php -m

$ php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
intl
json
ldap
libxml
mbstring
mysqli
mysqlnd
odbc
openssl
pcntl
pcre
PDO
pdo_dblib
pdo_mysql
PDO_ODBC
pdo_pgsql
pdo_sqlite
pgsql
Phar
phpdbg_webhelper
posix
pspell
readline
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

*根据需要安装扩展,以上所列出的扩展根据项目实际需要安装

$ pecl install 扩展名
4.php-fpm配置 php-fpm -v 查看版本
$ php-fpm -v
PHP 7.4.32 (fpm-fcgi) (built: Sep 29 2022 11:04:31)
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.32, Copyright (c), by Zend Technologies
5.测试一下php-fpm配置文件
$ php-fpm -t
[07-Oct-2022 21:45:06] NOTICE: configuration file /usr/local/etc/php/7.4/php-fpm.conf test is successful
6.修改配置文件

去掉pid = run/php-fpm.pid前的“;” 按键盘esc,再输入:wq回车保存退出

$ vim /usr/local/etc/php/7.4/php-fpm.conf
7.启动php-fpm
$ php-fpm -D
[07-Oct-2022 21:52:52] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
[07-Oct-2022 21:52:52] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
8.查看php-fpm进程:
$ ps aux | grep php-fpm
chenjin           2574   0.0  0.0 34353008   1088   ??  Ss    9:52下午   0:00.00 php-fpm -D
chenjin           2583   0.0  0.0 34122828    760 s000  R+    9:53下午   0:00.00 grep php-fpm
chenjin           2576   0.0  0.0 34352752    620   ??  S     9:52下午   0:00.00 php-fpm -D
chenjin           2575   0.0  0.0 34352752    656   ??  S     9:52下午   0:00.00 php-fpm -D
9.关闭php-fpm kill后面的数字对应进程的最后一项
$ kill 2575 
或者
$ kill -INT `cat /usr/local/var/run/php-fpm.pid`
10.重启php-fpm
$ kill -USR2 `cat /usr/local/var/run/php-fpm.pid`
11.设置开机启动php-fpm
$ ln -sfv /usr/local/opt/php@7.4/*.plist ~/Library/LaunchAgents
/Users/chenjin/Library/LaunchAgents/homebrew.mxcl.php@7.4.plist -> /usr/local/opt/php@7.4/homebrew.mxcl.php@7.4.plist
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php@7.4.plist
12.安装 composer
$ brew install composer

安装完成查看composer版本,看到以下信息则安装成功

$ composer -v
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.4.2 2022-09-14 16:11:15

二、安装NGINX

$ brew install nginx
1.测试nginx
$ nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
2.启动nginx
$ sudo nginx
或者
$ nginx
3.查看nginx运行状态
$ ps aux | grep nginx
chenjin           4542   0.0  0.0 34122828    832 s000  S+   10:21下午   0:00.00 grep nginx
chenjin           4537   0.0  0.0 34146388   1028   ??  S    10:21下午   0:00.00 nginx: worker process
chenjin           4536   0.0  0.0 34145940    492   ??  Ss   10:21下午   0:00.00 nginx: master process nginx
4.设置开启启动nginx
$ ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
5.重新加载配置|重启|停止|退出 nginx
$ nginx -s reload|reopen|stop|quit
或者用macOS自带的命令launchctl来启动或停止
停止:
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
启动:
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容