简体   繁体   English

自制软件在 Mac High Sierra 上的哪里安装 PHP?

[英]Where does homebrew install PHP on Mac High Sierra?

I'm using Mac High Sierra.我正在使用 Mac High Sierra。 I installed PHP (with GMP) using我使用安装 PHP

brew install php72-gmp

Everything installed successfully, per the messages given, but it would seem I still have an old version of PHP 7.1 somewhere on my machine because when I run根据给出的消息,一切都已成功安装,但我的机器上似乎仍有旧版本的 PHP 7.1,因为当我运行时

localhost:php-7.2.1 davea$ which php
/usr/bin/php
localhost:php-7.2.1 davea$ /usr/bin/php -v
PHP 7.1.7 (cli) (built: Jul 15 2017 18:08:09) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

So I'd like to figure out where to put the homebrew version of PHP ahead in my PATH so that that version gets picked up first.所以我想弄清楚在我的 PATH 中将 PHP 的自制版本放在哪里,以便首先选择该版本。

EDIT: 编辑:

As of 2018 and the latest updates to Brew your php formula names have the following format php@7.2 . 截至2018年以及Brew的最新更新,您的php公式名称的格式为php@7.2

When you run brew info php@7.2 your path should be /usr/local/Cellar/php@7.2/ 当您运行brew info php@7.2您的路径应为/usr/local/Cellar/php@7.2/

And there will be a symbolic link to /usr/local/bin/opt/php@7.2/ 并且将有一个符号链接到/usr/local/bin/opt/php@7.2/

So in order to change your php installation you just need to run this in terminal: 因此,为了更改您的php安装,您只需要在终端中运行此命令即可:

echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.bash_profile

or put it manually in your .bash_profile like this: 或像这样手动将其放入您的.bash_profile

export PATH="/usr/local/opt/php@7.2/bin:$PATH"
export PATH="/usr/local/opt/php@7.2/sbin:$PATH"

=========================================================================== ================================================== ========================

The location of your Homebrew installed php should be /usr/local/Cellar/php72 您的Homebrew安装的php的位置应为/usr/local/Cellar/php72

These are the steps you need to do to setup your PHP on macOS: 这些是在macOS上设置PHP所需执行的步骤:

After you install php with brew run this in terminal: 用brew安装php后,在终端运行此命令:

export PATH="$(brew --prefix homebrew/php/php72)/bin:$PATH"

Then run: 然后运行:

source ~/.bash_profile

To check your current active version of php run this in terminal: 要检查您当前的php有效版本,请在终端中运行此命令:

which php

EDIT: 编辑:

run brew info php72 in console to get all info, hints and caveats for php, it is really useful, for example this comes from brew info: 在控制台中运行brew info php72以获取php的所有信息,提示和警告,这确实很有用,例如,它来自brew info:

✩✩✩✩ PHP CLI ✩✩✩✩

If you wish to swap the PHP you use on the command line, you should add the 
following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent 
configuration file:
export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"

Check if you have two php directories in '/usr/bin/' or '/usr/local/bin/'. 检查“ / usr / bin /”或“ / usr / local / bin /”中是否有两个php目录。 If yes do a link to the good directory. 如果是,请链接到好目录。 See this link , may be it helps you. 看到此链接 ,可能对您有帮助。

As you are familiar with linux, homebrew has its own /opt and /etc path正如你所熟悉的 linux,homebrew 有自己的/opt/etc路径

/opt/homebrew/opt
/opt/homebrew/etc

in linux, php is installed in /etc/php/7.4在 linux 中,php 安装在/etc/php/7.4

in mac homebrew, php is installed in /opt/homebrew/etc/php/7.4在 mac homebrew 中,php 安装在/opt/homebrew/etc/php/7.4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM