MAC安装homebrew、php及其扩展

桓兴腾
2023-12-01

homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

替换homebrew国内镜像源

brew install --cask dosbox
  • 替换源
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

# 手动设置
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
git -C "$(brew --repo homebrew/cask-versions)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-versions.git
  • 复原源
# brew 程序本身,Homebrew / Linuxbrew 相同
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git

# 以下针对 macOS 系统上的 Homebrew
BREW_TAPS="$(brew tap)"
for tap in core cask{,-fonts,-drivers,-versions}; do
    if echo "$BREW_TAPS" | grep -qE "^homebrew/${tap}\$"; then
        git -C "$(brew --repo homebrew/${tap})" remote set-url origin https://github.com/Homebrew/homebrew-${tap}.git
    fi
done

安装php

  • 安装php
brew search php
brew install php@7.2

  • pecl安装扩展
pecl search redis
pecl install redis
pecl install swoole
# 安装指定包 http://pecl.php.net/package/swoole
pecl install http://pecl.php.net/get/swoole-4.6.1.tgz 

  • 安装PHP版本切换工具
brew install brew-php-switcher
brew install php@7.3
brew-php-switcher 7.3
  • 启动和停止php-fpm
brew services start php@7.2
brew services restart php@7.2
brew services stop php@7.2

编译安装php扩展

  • 例如安装 php trie-filter扩展
git clone https://github.com/zzjin/php-ext-trie-filter
cd php-ext-trie-filter/
/usr/local/bin/phpize
 # 如果php-config在$PATH下,可不用加--with-php-config,不在则指定
./configure  --with-php-config=/usr/local/bin/php-config
make
make install 
 # 添加扩展到php.ini
php -i|grep ini # 找到对应的php.ini地址 添加
vim php.ini
extension=trie_filter.so
 类似资料: