MacOs12.7.1安装LNMP环境
安装前先有梯子。自行寻找,可使用
https://xn–4gq62f52gdss.com/#/dashboard
安装HomeBrew
下载HomeBrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
添加环境变量,>>之后的位置根据自己电脑来看
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/yafeixiao/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
安装Nginx
安装
brew install nginx
管理命令
brew services start nginx
brew services stop nginx
brew services restart nginx
安装php7.4
由于brew最新版都是8.0以上的php,所以我们借助shivammathur/php
brew tap shivammathur/php
查看下有哪些版本支持
brew search php
执行安装
brew install shivammathur/php/php@7.4
增加环境变量
echo 'export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/php@7.4/lib"
export CPPFLAGS="-I/opt/homebrew/opt/php@7.4/include"
source ~/.zshrc
管理php命令
brew services start shivammathur/php/php@7.4
brew services stop shivammathur/php/php@7.4
brew services restart shivammathur/php/php@7.4
安装redis
brew install redis
管理redis命令
brew services start redis
brew services stop redis
brew services restart redis
安装mysql
下载
brew install mysql@8.0
环境变量
echo 'export PATH="/opt/homebrew/opt/mysql@8.0/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/mysql@8.0/lib"
export CPPFLAGS="-I/opt/homebrew/opt/mysql@8.0/include"
管理mysql
brew services start mysql@8.0
brew services stop mysql@8.0
brew services restart mysql@8.0
PHP安装redis扩展
一路回车即可
pecl install redis
PHP安装MongoDb扩展
pecl install mongodb
一路回车,报错:缺少pcre2.h文件,执行
brew install pcre
然后执行(具体根据你的实际路径)
cp /opt/homebrew/Cellar/pcre2/10.42/include/pcre2.h /opt/homebrew/Cellar/php\@7.4/7.4.33_5/include/php/ext/pcre/pcre2.h
PHP安装swoole4.8.13扩展
pecl install https://pecl.php.net/get/swoole-4.8.13.tgz
报错:/private/tmp/pear/temp/swoole/include/swoole_ssl.h:27:10: fatal error: ‘openssl/ssl.h’ file not found,找到openssl的位置,指定即可
➜ ~ pecl install swoole
...
enable sockets supports? [no] : yes
enable openssl support? [no] : yes --with-openssl-dir=/opt/homebrew/opt/openssl
...
报错:/private/tmp/pear/temp/swoole/ext-src/php_swoole.cc:55:10: fatal error: ‘ares.h’ file not found
首先确认c-ares是否安装,若未安装则执行
brew install c-ares
查看c-ares路径
brew info c-ares
编辑~/.bash_profile文件(确保位置正确)
export LDFLAGS="-L/opt/homebrew/Cellar/c-ares/1.23.0/lib"
export CPPFLAGS="-I/opt/homebrew/Cellar/c-ares/1.23.0/include"
source ~/.bash_profile
再次执行安装命令即可,在cares处输入yes即可
enable cares support? [no] : yes
PHP安装amqp扩展
第一步:
pecl install amqp
第二步:报错:librabbitmq不存在,执行:
brew install rabbitmq-c
第三步:安装完成后再次执行第一步,要求输入指定位置时写:
/opt/homebrew/Cellar/rabbitmq-c/0.13.0
回车就可以了
第二步也可执行
brew install rabbitmq
这样会把rabbitmq服务端也安装上,同时rabbitmq-c也会被安装
rabbitmq安装完成后默认账号密码为:guest guest
最后
重启php,输入php -m就可以看到以上的扩展了,输入brew services list也可看到你通过brew安装的所有软件