简体   繁体   English

zsh:找不到命令:php

[英]zsh: command not found: php

I have been using php with mamp on mac for a year even with old versions of MacOS, since I installed MacOS Monterrey if I type php on the terminal I get a message: zsh: command not found: php即使使用旧版本的 MacOS,我也一直在 Mac 上使用带有 mampphp一年,因为如果我在终端上键入php ,我安装了MacOS Monterrey ,我收到一条消息: zsh: command not found: php

Using older versions of MacOS I have never had this problem.使用旧版本的 MacOS 我从来没有遇到过这个问题。

How can I solve the problem?我该如何解决这个问题?

When I update MacOS Monterey, PHP was remove.当我更新 MacOS Monterey 时,PHP 被删除。 I found this article it useful and solve this problem for me.我发现这篇文章很有用并为我解决了这个问题。 https://wpbeaches.com/updating-to-php-versions-7-4-and-8-on-macos-12-monterey https://wpbeaches.com/updating-to-php-versions-7-4-and-8-on-macos-12-monterey

Add the PHP formulae添加 PHP 公式

brew tap shivammathur/php

Choose the PHP version – this example uses 7.4选择 PHP 版本——本例使用 7.4

brew install shivammathur/php/php@7.4

Link the PHP Version链接 PHP 版本

brew link --overwrite --force php@7.4

Restart the Terminal重启终端

php -v

I had the same issue after updating to Monterry.更新到蒙特里后我遇到了同样的问题。 After some googling, I find out MacOS doesn't include PHP.经过一番谷歌搜索,我发现 MacOS 不包含 PHP。 You need Homebrew to install PHP again.您需要 Homebrew 重新安装 PHP。

brew install php

https://daily-dev-tips.com/posts/installing-php-on-your-mac/https://daily-dev-tips.com/posts/installing-php-on-your-mac/

Homebrew users:自制用户:

This can happen simply because your php version is not linked.这可能只是因为您的 php 版本未链接而发生。

Goto /usr/local/Cellar, list out the content and see what versions of php you have installed.转到 /usr/local/Cellar,列出内容并查看您安装的 php 版本。 You should see directories and symlinks as so:您应该看到目录和符号链接,如下所示:

lrwxr-xr-x    1 kazajhodo  admin      7 May 22  2019 php72 -> php@7.2
lrwxr-xr-x    1 kazajhodo  admin      7 Feb 26  2020 php73 -> php@7.3
lrwxr-xr-x    1 kazajhodo  admin      7 Jun 12  2020 php74 -> php@7.4
lrwxr-xr-x    1 kazajhodo  admin      7 Jan 22  2021 php80 -> php@8.0
lrwxr-xr-x    1 kazajhodo  admin      7 Jan  4 11:58 php81 -> php@8.1
drwxr-xr-x    3 kazajhodo  staff     96 Jan  4 11:34 php@7.2
drwxr-xr-x    3 kazajhodo  staff     96 Aug  8 19:32 php@7.3
drwxr-xr-x    4 kazajhodo  staff    128 Jan  4 11:55 php@7.4
lrwxr-xr-x    1 kazajhodo  admin     18 Jan 22  2021 php@8.0 -> /usr/local/bin/php
lrwxr-xr-x    1 kazajhodo  admin     18 Jan  4 11:58 php@8.1 -> /usr/local/bin/php

If the version you want is there, you can link it with brew link php@7.4 .如果你想要的版本在那里,你可以用brew link php@7.4链接它。

Then your bash should have php defined.然后你的 bash 应该有 php 定义。

Installing php again will also work, because it will add the symlink in the install process;再次安装php也可以,因为它会在安装过程中添加符号链接; but you only likely actually need the symlink.但您实际上可能只需要符号链接。

I have same problem and this is the solution that I use for this.我有同样的问题,这是我使用的解决方案。

  1. install Xcode using your terminal使用终端安装 Xcode

     xcode-select --install
  2. install homebrew using your terminal使用终端安装自制软件

     /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    when it finish the process you need to add the homebrew in your path and for this put this code当它完成该过程时,您需要在路径中添加自制软件,为此放置此代码

     echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/**xxxxxxx**/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)"

    xxxxxxx write your user name xxxxxxx写下你的用户名

    now you can check if homebrew is run correctly, use the next code.现在您可以检查自制程序是否正确运行,使用下一个代码。

     brew --version

    you can see in the terminal the version that you have install in your pc您可以在终端中看到您在电脑中安装的版本

  3. now is time for install php for this现在是时候为此安装php了

     brew install php

    finally, you can try see the version of php installed最后,您可以尝试查看安装的php版本

     php --version

If you want the latest PHP release in macOS Monterey then follow these steps:如果您想要 macOS Monterey 中的最新 PHP 版本,请按照以下步骤操作:

1: brew tap shivammathur/php 1: brew tap shivammathur/php

2: brew install shivammathur/php/php@8.2 2: brew install shivammathur/php/php@8.2

3: brew link --overwrite --force php@8.2 3: brew link --overwrite --force php@8.2

to check if its working, write this in the terminal: php -v要检查它是否工作,请在终端中写入: php -v

if you get something along the lines of PHP 8.2.0-dev (cli) then its working如果你得到一些符合PHP 8.2.0-dev (cli)的东西,那么它的工作原理

我需要安装 php :D

brew install php

When I have tried to install composer for laravel 8 on XAMPP localhost (on Macbook pro- on the path /Applications/XAMPP/xamppfiles/htdocs/the my project folder), and when I have run first command: php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"当我尝试在 XAMPP 本地主机上为 laravel 8 安装 composer 时(在 Macbook pro 上的路径 /Applications/XAMPP/xamppfiles/htdocs/我的项目文件夹),并且当我运行第一个命令时: php -r "copy( 'https://getcomposer.org/installer', 'composer-setup.php');"

I have gotten this message in command line (terminal): -bash: /Applications/MAMP/bin/php/php7.4.16/bin/php: No such file or directory我在命令行(终端)中收到此消息:-bash: /Applications/MAMP/bin/php/php7.4.16/bin/php: No such file or directory

For that, I installed localhost MAMP为此,我安装了本地主机 MAMP

Also, I noticed php7.4.16 is in path, but I'm using ver 8.另外,我注意到 php7.4.16 在路径中,但我使用的是 ver 8。

and when I installed php7.4.16 also, when I opened its folder, I found its subfolders are different of other versions that exist in /MAMP/bin/php , and it doesn't contain same folders in the rest of path , further to, this version is not supported longer.当我也安装 php7.4.16 时,当我打开它的文件夹时,我发现它的子文件夹与 /MAMP/bin/php 中存在的其他版本不同,并且它在路径的其余部分不包含相同的文件夹,进一步到,此版本不再受支持。

why this version shows in my installation path although it's old & dead version?为什么这个版本显示在我的安装路径中,尽管它是旧的和死的版本?

But, when I read the problem has posted here, I have tried to install brew , it issues for me the following message:但是,当我阅读这里发布的问题时,我尝试安装brew ,它向我发出以下消息:

Warning: You are using macOS 10.13.警告:您使用的是 macOS 10.13。 We (and Apple) do not provide support for this old version.我们(和 Apple)不提供对这个旧版本的支持。 You will encounter build failures with some formulae.您会遇到一些公式的构建失败。 Please create pull requests instead of asking for help on Homebrew's GitHub, Twitter or any other official channels.请创建拉取请求,而不是在 Homebrew 的 GitHub、Twitter 或任何其他官方渠道上寻求帮助。 You are responsible for resolving any issues you experience while you are running this old version.您有责任解决在运行此旧版本时遇到的任何问题。

So, it's not Possible to install it, because my MacOS is 10.13, and my computer specifications don't allow to upgrade to higher ver.因此,无法安装它,因为我的 MacOS 是 10.13,并且我的计算机规格不允许升级到更高版本。

kindly, anybody could help me to solve this problem?好心,有人可以帮我解决这个问题吗?

Also, could me to install composer on XAMPP instead of MAMP, because I have a copy of it on my MacBook computer already?另外,我可以在 XAMPP 而不是 MAMP 上安装 composer 吗,因为我的 MacBook 电脑上已经有了它的副本?

Thank you for my helping in advance.提前感谢您对我的帮助。

You have to edit the file .zshrc您必须编辑文件 .zshrc

vim ~/.zshrc

and Then you update the path for your php然后你更新你的php的路径

type on "?"输入“?” search "php" ... type enter, it will show you the line where php is.搜索“php” ...输入回车,它将显示php所在的行。 If not you have to add the path of your PHP.如果不是,您必须添加 PHP 的路径。

You use Mamp, then it should on the root of mamp.你使用 Mamp,那么它应该在 mamp 的根目录上。 set it on your .zshrc在你的 .zshrc 上设置它

This my .zshrc related to php :这是我的 .zshrc 与 php 相关:

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

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

Just using brew install php will install the latest php in mac.只需使用brew install php将在 mac 中安装最新的 php。 You can then enable php in Apache by adding the following to httpd.conf and restart Apache:然后,您可以通过将以下内容添加到 httpd.conf 并重新启动 Apache 来启用 Apache 中的 php:

LoadModule php_module/usr/local/opt/php/lib/httpd/modules/libphp.so

You probably need to fix it in the .bashrc file.您可能需要在.bashrc文件中修复它。

Do this:做这个:

Open the terminal and run this command:打开终端并运行以下命令:

nano ~/.bashrc 

Then add this line in the .bashrc file:然后在.bashrc文件中添加这一行:

export PATH=$PATH:/usr/share/php/bin

Save and exit ( ctrl + x )保存并退出( ctrl + x

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

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