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

这篇具有很好参考价值的文章主要介绍了MAC 安装PHP及环境配置 保姆级别。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

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是不会自己保存生效的

需要: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模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Mac上使用phpstudy+vscode配置PHP开发环境

    1、系统版本 2、vs code code 3、phpstudy_pro 1、vs code下载 点击vs code官网下载 选择对应的版本,一般电脑会自动识别对应的版本,点击下载,然后傻瓜式安装! 2、vs code 的插件安装 点击下面的图标,扩展 搜索“Chinese”,然后点击“install”,等待安装 安装完成右下角显示,点击

    2024年01月23日
    浏览(66)
  • Mac上Maven的安装和环境变量配置保姆级教程(最新版实时更新)

    目录 一、Maven的安装 1.进入官网(Maven官网)下载安装包并解压 2.这里我使用了Homebrew安装Maven 安装Homebrew: 安装Maven: 二、Maven配置环境变量 1.打开环境变量文档: 2.在弹出文档结尾加入配置: 3.保存变量配置: 4.验证安装结果: 三、配置本地仓库 1.什么是本地仓库 2.配置步

    2024年04月25日
    浏览(62)
  • Mac 安装php多版本,brew安装php8.0

     因为需要我要在mac上装两个php版本,先前我已经装过php7.4,下面我们逐步安装php8.0 直接运行安装  brew install php@8.0 遇到问题怀疑是仓库太老了,更新一下homebrew ,重新安装 brew update 安装成功了,不过看了下版本好像不能正常打印版本了  报错相关文档,查询了下好像是icu4c 这个

    2024年02月10日
    浏览(34)
  • mac 安装 php 8.1

    mac默认安装的php版本可能偏低,可以按照以下步骤安装最新的php 8.1。 首先安装homebrew,如已经安装,忽略 将 php 8.1 的路径添加到 PATH 查看php版本,可以发现php已经是新版本了 php -v 查看PHP的服务 brew services list php --ini 配置文件 /opt/homebrew/etc/php/8.1/php.ini 附加.ini 配置文件目录

    2024年02月07日
    浏览(34)
  • Mac PHP7.4安装

    查看可按照版本: 使用brew安装: 但报错: Error: php@7.4 has been disabled because it is a versioned formula! 这是因为php7.4官方已经不再维护,所以Hombrew将该php版本移出了repository,所以安装不了。 解决方案 从第三方仓库中安装 比如(所有旧版php仓库地址https://github.com/shivammath…)

    2024年02月13日
    浏览(41)
  • mac安装php的redis扩展

    1,下载php-redis 2,安装并编译 3,修改php.ini 4,验证是否安装成功 打开phpinfo页面,查找Redis选项,如下图代表安装成功。  

    2024年02月13日
    浏览(45)
  • mac brew 安装php7.4

    查看可按照版本: brew search php 使用brew安装: brew install php@7.4 但报错: Error: php@7.4 has been disabled because it is a versioned formula! 这是因为php7.4官方已经不再维护,所以Hombrew将该php版本移出了repository,所以安装不了。 解决方案 从第三方仓库中安装 比如(所有旧版php仓库地址https

    2024年02月10日
    浏览(30)
  • 保姆级别——Android Studio安装教程&环境变量配置

    1.1 官网下载地址: Download Android Studio and SDK tools  |  Android Developers 1.2 找到下载好的安装包,双击,再按以下步骤操作。 1.3 这里点击Browse更换安装路径(推荐),也可以安装在默认路径下。 1.4 安装完成后勾选Start Android Studio启动并点击finish。  1.5 启动完成选择不导入配置,然

    2024年02月16日
    浏览(45)
  • Mac m1 安装rabbitmq+php-amqplib

    rabbitmq 官方地址 https://www.rabbitmq.com mac 软件包 Downloading and Installing RabbitMQ — RabbitMQ 一.这里我选择 homebrew  二.php代码 用composer 安装 10年软件开发经验,结交朋友! 分销商城系统开发,App商城开发 商务合作 samshop168 欢迎私信,必回

    2024年02月09日
    浏览(32)
  • Mac系统配置环境变量保姆级教程

    1、下载好相关安装包 2、打开终端,输入命令转到系统环境变量配置文件 输入密码(密码不显示,实际上已经在输入了)  3、替换配置文件中PATH后的部分,改为包的位置,按键盘a进入编辑模式 即替换/Library/Frameworks/Python.framework/Versions/3.7/bin为自己电脑中的位置  4、修改好

    2024年02月11日
    浏览(52)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包