Search"/>

文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

MAC 安装PHP及环境配置 保姆级别

2023-09-02 17:50

关注

首先命令行进行安装

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...==> Formulaephp@8.1     php@8.0     php@7.4To install php@8.1, run:  brew install php@8.1

出现该问题的原因安装的版本问题,根据提示进行下载安装对应的版本即可

b、出现error

fatal: not in a git directoryError: Command failed with exit 128: git

解决办法:直接运行brew -v

brew -v
mark@192 ~ % brew -vHomebrew 4.0.19-9-g8aaf99efatal: 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-coreHomebrew/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-caskHomebrew/homebrew-cask (no Git repository)

看到有两个git config,分别运行一下即可,如下

mark@192 ~ % git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-coremark@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 secondsWarning: 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.gzAlready 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.gzAlready 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.gzAlready 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`).

完成之后,接着去安装就好了

配置环境 

安装完成之后,这个时候直接 php -v 是无法找到这个命令的

zsh: command not found: php

需要把这个安装好的php配置到运行环境

vi ~/.bashrc

在安装完php的时候,最后部分有提示

==> php@8.0To 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            SetHandler application/x-httpd-php    Finally, check DirectoryIndex includes index.php    DirectoryIndex index.php index.htmlThe 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"' >> ~/.zshrcFor 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.0Or, 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是不会自己保存生效的

需要:source ~/.bashrc 最后到这里,你自己安装的PHP环境就OK了

mark@192 ~ % php -v          PHP 8.0.28 (cli) (built: Feb 14 2023 15:42:52) ( NTS )Copyright (c) The PHP GroupZend Engine v4.0.28, Copyright (c) Zend Technologies    with Zend OPcache v8.0.28, Copyright (c), by Zend Technologies

来源地址:https://blog.csdn.net/ahualong1/article/details/130844112

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯