MacBook Pro m1安装swoole PHP版本7.4

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

  1. 如果出现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
    
  2. 出现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的扩展