1.文档阅读 The Missing Package Manager for macOS (or Linux) — Homebrew macOS(或 Linux)缺失的软件包的管理器 — Homebrew macOS Monterey 移除了自带的 PHP Upgrade vs. Update · Issue #13064 · Homebrew/legacy-homebrew · GitHub -- 关于brew update vs upgrade的事情 Issues · Homebrew/brew · GitHub brew install 和 brew cask install 的区别 - 知乎 2.整理输出 前言交代 因为Mac升级OS到12.1 不再支持内置各个编程语言的运行时环境,本人又有些不像单独安装。 干脆就安装Mac的软件管理器,如果电脑感到卡,再卸载。 PHP: 使用 macOS Monterey 之前内置的 PHP - Manual 2.1 安装 homebrew 终端中执行如下命令即可 /bin/bash -c "$(curl -fsSL .sh)" 升级之后 ➜ ~ brew -v Homebrew 3.6.7 Homebrew/homebrew-core (git revision a99c43cbe3f; last commit 2022-10-29) Homebrew/homebrew-cask (git revision 0441adcaf2; last commit 2022-10-29) ➜ ~ 注意 有时候,需要科学上网才行,使用国内源进行安装 /bin/bash -c "$(curl -fsSL .sh)" 下载安装过程如下: huangbaoyin@huangbaoyindeMacBook-Pro ~ % /bin/bash -c "$(curl -fsSL .sh)" 开始执行Brew自动安装程序 [cunkai.wang@foxmail] ['2022-08-19 16:51:27']['12.5'] 请选择一个下载brew本体的序号,例如中科大,输入1回车。 源有时候不稳定,如果git克隆报错重新运行脚本选择源。 1、中科大下载源 2、清华大学下载源 3、北京外国语大学下载源 4、腾讯下载源 5、阿里巴巴下载源 请输入序号: 1 你选择了中国科学技术大学brew本体下载源 !!!此脚本将要删除之前的brew(包括它下载的软件),请自行备份。 ->是否现在开始执行脚本(N/Y) Y --> 脚本开始执行 Mac os设置开机密码方法: (设置开机密码:在左上角苹果图标->系统偏好设置->用户与群组->更改密码) (如果提示This incident will be reported. 在用户与群组中查看是否管理员) ==> 通过命令删除之前的brew、创建一个新的Homebrew文件夹 请输入开机密码,输入过程不显示,输入完后回车 开始执行 ---备份要删除的/opt/homebrew到系统桌面.... ---/opt/homebrew 备份完成 -> 创建文件夹 /opt/homebrew 运行代码 ==> /usr/bin/sudo /bin/mkdir -p /opt/homebrew 此步骤成功 运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /opt/homebrew 运行代码 ==> /usr/bin/sudo /usr/sbin/chown huangbaoyin /opt/homebrew 运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /opt/homebrew git version 2.32.1 (Apple Git-133) 下载速度觉得慢可以ctrl+c或control+c重新运行脚本选择下载源 ==> 从 .git 克隆Homebrew基本文件 未发现Git代理(属于正常状态) Cloning into '/opt/homebrew'... remote: Enumerating objects: 221996, done. remote: Total 221996 (delta 0), reused 0 (delta 0), pack-reused 221996 Receiving objects: 100% (221996/221996), 59.40 MiB | 10.96 MiB/s, done. Resolving deltas: 100% (164896/164896), done. 此步骤成功 --创建Brew所需要的目录 运行代码 ==> /usr/bin/sudo /bin/chmod u+rwx /opt/homebrew/bin /opt/homebrew/bin/brew .... .... 简单截图 记得重启终端窗口或者执行: source /Users/huangbaoyin/.zprofile 但是在安装PHP时,一直提示出现apr的报错 最后还是使用科学上网的方式,重新安装了homebrew, 执行brew install php 解决 插入 关于brew的命令应该熟练使用,各个命令的含义用途 -- 没有几个,而且最常用的有 红色 标记 ➜ ~ brew -h Example usage: brew search TEXT|/REGEX/ // 在homebrew中搜索有关所有软件信息 brew info [FORMULA|CASK...] // 查看软件的信息「最新版本」 brew install FORMULA|CASK... // 安装软件「默认最新版本」 brew update // 更新homebrew版本及软件索引 brew upgrade [FORMULA|CASK...] // 更新homebrew已安装的所有软件「如果已经是最新版,会跳过」 brew uninstall FORMULA|CASK... // 卸载使用homebrew安装的软件 brew list [FORMULA|CASK...] // 查看使用homebrew安装过软件列表 Troubleshooting: brew config brew doctor brew install --verbose --debug FORMULA|CASK Contributing: brew create URL [--no-fetch] brew edit [FORMULA|CASK...] Further help: brew commands brew help [COMMAND] man brew ➜ ~ FORMULA|CASK ==== 配方|桶 一时记不住具体的命令时 或者 根本不知道怎么使用命令时 「很多系统,软件都支持这样」 首先,可以借助帮助命令 brew -h 然后,具体对某一个命令进行查看 brew list -h 之后,快速扫描到目标,然后详细查看具体使用 如下: ➜ ~ brew -h Example usage: brew search TEXT|/REGEX/ brew info [FORMULA|CASK...] brew install FORMULA|CASK... brew update brew upgrade [FORMULA|CASK...] brew uninstall FORMULA|CASK... brew list [FORMULA|CASK...] Troubleshooting: brew config brew doctor brew install --verbose --debug FORMULA|CASK Contributing: brew create URL [--no-fetch] brew edit [FORMULA|CASK...] Further help: brew commands brew help [COMMAND] man brew ➜ ~ brew list -h Usage: brew list, ls [options] [installed_formula|installed_cask ...] List all installed formulae and casks. // 列出所有已安装的配方和容器 -- 就是列出所有使用homebrew安装的软件 If formula is provided, summarise the paths within its current keg. If cask is provided, list its artifacts. --formula, --formulae List only formulae, or treat all named arguments as formulae. --cask, --casks List only casks, or treat all named arguments as casks. --full-name Print formulae with fully-qualified names. Unless --full-name, --versions or --pinned are passed, other options (i.e. -1, -l, -r and -t) are passed to ls(1) which produces the actual output. --versions Show the version number for installed formulae, or only the specified formulae if formula are provided. --multiple Only show formulae with multiple versions installed. --pinned List only pinned formulae, or only the specified (pinned) formulae if formula are provided. See also pin, unpin. -1 Force output to be one entry per line. This is the default when output is not to a terminal. -l List formulae and/or casks in long format. Has no effect when a formula or cask name is passed as an argument. -r Reverse the order of the formulae and/or casks sort to list the oldest entries first. Has no effect when a formula or cask name is passed as an argument. -t Sort formulae and/or casks by time modified, listing most recently modified first. Has no effect when a formula or cask name is passed as an argument. -d, --debug Display any debugging information. -q, --quiet Make some output more quiet. -v, --verbose Make some output more verbose. -h, --help Show this message. ➜ ~ 然后,就可以使用 ➜ ~ brew list 大致浏览下,已经安装过什么软件。 如果使用的时候,不记得是否安装过, 可使用 brew list | grep 软件名 或者 brew info 软件名 // 如果没有安装,输出信息中会有提示:Not installed 以wget 和 mysql为例 2.2 安装PHP PHP: 使用软件包 - Manual 终端中执行 brew install php 关键信息: To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> Finally, check DirectoryIndex includes index.php DirectoryIndex index.php index.html The php.ini and php-fpm.ini file can be found in: /usr/local/etc/php/8.1/ To restart php after an upgrade: brew services restart php Or, if you don't want/need a background service you can just run: /usr/local/opt/php/sbin/php-fpm --nodaemonize 查看PHP版本 ➜ php-test-temp php -v PHP 8.1.1 (cli) (built: Dec 17 2021 22:38:05) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.1, Copyright (c) Zend Technologies with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies ➜ php-test-temp 查看扩展文件目录 ➜ php-test-temp php-config --extension-dir /usr/local/Cellar/php/8.1.1/pecl/20210902 ➜ php-test-temp 查看配置文件目录 ➜ 8.1 ls conf.d pear.conf php-fpm.conf php-fpm.d php.ini ➜ 8.1 pwd /usr/local/etc/php/8.1 ➜ 8.1 ➜ php-test-temp php-config --ini-dir /usr/local/etc/php/8.1/conf.d 补充 安装不同的PHP版本,以及使用PHP版本 1. brew search php // 查看homebrew源支持的PHP本本 2. 安装PHP另一版本[项目需要] === PHP 7.2 这里已经安装了PHP 8.1 ➜ ~ brew install php@7.2 出现报错 解决方法 homebrew - Error: php@7.3 has been disabled because it is a versioned formula - Stack Overflow brew tap shivammathur/php brew install shivammathur/php/php@7.2 截图 输出的关键信息 ... To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> Finally, check DirectoryIndex includes index.php DirectoryIndex index.php index.html The php.ini and php-fpm.ini file can be found in: /usr/local/etc/php/7.2/ php@7.2 is keg-only, which means it was not symlinked into /usr/local, because this is an alternate version of another formula. If you need to have php@7.2 first in your PATH, run: echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.zshrc For compilers to find php@7.2 you may need to set: export LDFLAGS="-L/usr/local/opt/php@7.2/lib" export CPPFLAGS="-I/usr/local/opt/php@7.2/include" To restart shivammathur/php/php@7.2 after an upgrade: brew services restart shivammathur/php/php@7.2 Or, if you don't want/need a background service you can just run: /usr/local/opt/php@7.2/sbin/php-fpm --nodaemonize ==> Summary 🍺 /usr/local/Cellar/php@7.2/7.2.34_4: 515 files, 75.0MB ==> Running `brew cleanup php@7.2`... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`). ➜ ~ 由于信息可知,安装目录在 /usr/local/opt/php@7.2 使用PHP 7.2启动Web服务 /usr/local/opt/php@7.2/bin/php -S localhost:8000 -t ./web 使用PHP 8.1启动Web服务 /usr/local/opt/php@8.1/bin/php -S localhost:8000 -t ./web 或 /usr/local/opt/php/bin/php -S localhost:8000 -t ./web 或 php -S localhost:8000 -t ./web 至于切换不同PHP的工具,TBD 后续补充 ... |
发表评论