Mac m1安裝mnmp(Mac,nginx,mysql,php)
使用brew來安裝php,nginx,mysql
# 搜索php的版本
brew search php
# 下載php
brew install php@7.4
# 加載到 .zshrc
export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"
export PATH="/opt/homebrew/opt/php@7.4/sbin:$PATH"
# 使之有效
source ~/.zshrc
# 檢測是否安裝完成
php -v
# 查找ini
php --ini
brew install nginx
# 安裝成功后,查看nginx信息
brew info nginx
# 最主要的是查看網站根目錄和配置文件目錄,默認為8080端口
# nginx 常用命令
sudo nginx # 啟動
sudo -s reload # 重新加載配置
sudo -s reopen # 重啟
sudo -s stop # 停止
sudo -s quit # 退出
brew install mysql@5.7
# 添加mysql到環境變量
echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
# 刷新
source ~/.zshrc
# 查看當前版本
mysql --version
# 沒有提示你默認密碼是多少 通過下面的命令直接修改密碼
mysqladmin -u root password "你的密碼"
# 然后重啟mysql服務
mysql.server restart
最后安裝swoole
先推薦一波EasySwoole的安裝方式
https://www.easyswoole.com/QuickStart/installSwoole.html
# 找到自己的php路徑
which php
# 進入swoole下載的文件目錄,使用當前php版本的進行phpize
phpize
# 創建編譯文件
./configure --with-php-config=/opt/homebrew/opt/php@7.4/bin/php-config --with-openssl-dir=/opt/homebrew/Cellar/openssl@1.1/1.1.1j --enable-http2 --enable-thread-context
這里的php選擇你對應的php目錄
如果出現openssl的問題,就如同我的一樣直接加載到openssl的目錄
最后想要在m1里編譯成功,加上了
--enable-thread-context
-
如果出現
pcre2.h問題# 建立軟鏈 根據自己電腦的實際pcre存在的地方和php對應的地方進行修改 sudo ln -s /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php@7.4/7.4.16/include/php/ext/pcre/pcre2.h沒有
pcre# 直接安裝 brew install pcre # 或者 brew reinstall pcre -
出現
openssl的問題# 仔細對一下配置的編譯文件里的自己的openssl的目錄是否正確
最后進行編譯
make clean
sudo make && make install
# 不出上述兩個意外的話,應該會成功
成功之后,將swoole.so加入到php.ini中
# 找到自己的當前php版本的所在ini
php --ini
最后驗證是否成功
php --ri swoole
# 出現以下內容
swoole
Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.4.23
Built => Jan 23 2021 18:16:30
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.0.2k-fips 26 Jan 2017
http2 => enabled
pcre => enabled
zlib => 1.2.7
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled
Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
# 則說明完成安裝swoole的擴展
