1、首先命令行进行安装
brew install php@8.0
第一次安装可能会出现的问题
a、安装版本问题
Warning: No available formula with the name "php@8.4". Did you mean php@8.1, php@8.0 or php@7.4?
==> Searching for similarly named formulae and casks...
==> Formulae
php@8.1 php@8.0 php@7.4
To install php@8.1, run:
brew install php@8.1
出现该问题的原因安装的版本问题,根据提示进行下载安装对应的版本即可
b、出现error
fatal: not in a git directory
Error: Command failed with exit 128: git
解决办法:直接运行brew -v
brew -v
mark@192 ~ % brew -v
Homebrew 4.0.19-9-g8aaf99e
fatal: detected dubious ownership in repository at '/opt/homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: detected dubious ownership in repository at '/opt/homebrew/Library/Taps/homebrew/homebrew-cask'
To add an exception for this directory, call:
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)
看到有两个git config,分别运行一下即可,如下
mark@192 ~ % git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
mark@192 ~ % git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
完成之后在运行:arch -arm64 brew install cocoapods
mark@192 ~ % arch -arm64 brew install cocoapods
运行结果
==> Downloading https://formulae.brew.sh/api/formula.jws.json
################################################################################################################### 58.8%curl: (28) Operation too slow. Less than 100 bytes/sec transferred the last 5 seconds
Warning: formula.jws.json: update failed, falling back to cached version.
==> Downloading https://formulae.brew.sh/api/formula.jws.json
##################################################################################################################################################################################################### 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
##################################################################################################################################################################################################### 100.0%
Warning: Treating cocoapods as a formula. For the cask, use homebrew/cask/cocoapods
==> Fetching dependencies for cocoapods: libyaml, ca-certificates, openssl@1.1, readline and ruby
==> Fetching libyaml
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/libyaml-0.2.5.arm64_ventura.bottle.tar.gz
##################################################################################################################################################################################################### 100.0%
==> Fetching ca-certificates
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/ca-certificates-2023-01-10.all.bottle.tar.gz
Already downloaded: /Users/mark/Library/Caches/Homebrew/downloads/08486bb5b9927def5c947c5a9e4a873eacd6364ac9cf6e50bfe3aa0bfc1c63ed--ca-certificates-2023-01-10.all.bottle.tar.gz
==> Fetching openssl@1.1
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/openssl%401.1-1.1.1t.arm64_ventura.bottle.tar.gz
Already downloaded: /Users/mark/Library/Caches/Homebrew/downloads/339aa132aee19ced825e32e534324ac7fddc1948efbf19216760c835d71c395b--openssl@1.1-1.1.1t.arm64_ventura.bottle.tar.gz
==> Fetching readline
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/readline-8.2.1.arm64_ventura.bottle.tar.gz
Already downloaded: /Users/mark/Library/Caches/Homebrew/downloads/61eadcc12bccc526220de0af71471c1f84d36861ce68a1e85979887e904b4e56--readline-8.2.1.arm64_ventura.bottle.tar.gz
==> Fetching ruby
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/ruby-3.2.2.arm64_ventura.bottle.tar.gz
##################################################################################################################################################################################################### 100.0%
==> Fetching cocoapods
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/cocoapods-1.12.1.arm64_ventura.bottle.tar.gz
##################################################################################################################################################################################################### 100.0%
==> Installing dependencies for cocoapods: libyaml, ca-certificates, openssl@1.1, readline and ruby
==> Installing cocoapods dependency: libyaml
==> Pouring libyaml-0.2.5.arm64_ventura.bottle.tar.gz
🍺 /opt/homebrew/Cellar/libyaml/0.2.5: 10 files, 351.2KB
==> Installing cocoapods dependency: ca-certificates
==> Pouring ca-certificates-2023-01-10.all.bottle.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
🍺 /opt/homebrew/Cellar/ca-certificates/2023-01-10: 3 files, 216.8KB
==> Installing cocoapods dependency: openssl@1.1
==> Pouring openssl@1.1-1.1.1t.arm64_ventura.bottle.tar.gz
🍺 /opt/homebrew/Cellar/openssl@1.1/1.1.1t: 8,101 files, 18MB
==> Installing cocoapods dependency: readline
==> Pouring readline-8.2.1.arm64_ventura.bottle.tar.gz
🍺 /opt/homebrew/Cellar/readline/8.2.1: 50 files, 1.7MB
==> Installing cocoapods dependency: ruby
==> Pouring ruby-3.2.2.arm64_ventura.bottle.tar.gz
🍺 /opt/homebrew/Cellar/ruby/3.2.2: 16,605 files, 48.3MB
==> Installing cocoapods
==> Pouring cocoapods-1.12.1.arm64_ventura.bottle.tar.gz
🍺 /opt/homebrew/Cellar/cocoapods/1.12.1: 13,430 files, 27.8MB
==> Running `brew cleanup cocoapods`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
完成之后,接着去安装就好了
2、配置环境
安装完成之后,这个时候直接 php -v 是无法找到这个命令的
zsh: command not found: php
需要把这个安装好的php配置到运行环境
vi ~/.bashrc
在安装完php的时候,最后部分有提示
==> php@8.0
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /opt/homebrew/opt/php@8.0/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:
/opt/homebrew/etc/php/8.0/
php@8.0 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
If you need to have php@8.0 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/php@8.0/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/php@8.0/sbin:$PATH"' >> ~/.zshrc
For compilers to find php@8.0 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/php@8.0/lib"
export CPPFLAGS="-I/opt/homebrew/opt/php@8.0/include"
To start php@8.0 now and restart at login:
brew services start php@8.0
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/php@8.0/sbin/php-fpm --nodaemonize
把下面两行放到 打开的bashrc文件中
export PATH="/opt/homebrew/opt/php@8.0/bin:$PATH"
export PATH="/opt/homebrew/opt/php@8.0/sbin:$PATH"
:wq 保存并退出
bashrc是不会自己保存生效的文章来源:https://www.toymoban.com/news/detail-671793.html
需要:source ~/.bashrc 最后到这里,你自己安装的PHP环境就OK了文章来源地址https://www.toymoban.com/news/detail-671793.html
mark@192 ~ % php -v
PHP 8.0.28 (cli) (built: Feb 14 2023 15:42:52) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.28, Copyright (c) Zend Technologies
with Zend OPcache v8.0.28, Copyright (c), by Zend Technologies
到了这里,关于MAC 安装PHP及环境配置 保姆级别的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!