iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > PHP编程 >MAC 安装PHP及环境配置 保姆级别
  • 720
分享到

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

macosphp 2023-09-02 17:09:33 720人浏览 独家记忆
摘要

首先命令行进行安装 brew install PHP@8.0 第一次安装可能会出现的问题 a、安装版本问题 Warning: No available formula with the name "php@8.4". Did you mea

首先命令行进行安装

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

--结束END--

本文标题: MAC 安装PHP及环境配置 保姆级别

本文链接: https://www.lsjlt.com/news/391142.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作