简体   繁体   English

已安装 PHP 7.0,但版本未更改

[英]PHP 7.0 installed, but version doesn't change

I'm trying to install PHP 7.0, which works.我正在尝试安装有效的 PHP 7.0。 But when I check my php -v in the cmd, it still says 5.5.36.但是当我在 cmd 中检查我的php -v时,它仍然显示 5.5.36。

I tried it via php-liip, homebrew, install manually and via cmd.我通过 php-liip、自制软件、手动安装和 cmd 进行了尝试。 Nothing works.什么都行不通。 When I change version of PHP in MAMP (which I work with to try and install composer in a directory, that I need PHP 5.6 or higher for) i still doesn't matter.当我在 MAMP 中更改 PHP 版本时(我使用它来尝试在目录中安装 Composer,我需要 PHP 5.6 或更高版本)我仍然无关紧要。

The PHP 5.5 you're seeing was installed by Apple and is a default on your computer.您看到的 PHP 5.5 是由 Apple 安装的,并且是您计算机上的默认版本。 It was installed at /usr/bin/php .它安装在/usr/bin/php

All of the installers you've used will not overwrite Apple's default installation - they will instead opt to create their own directories or use /usr/local/bin/ instead (thus the PHP interrupter would be installed at /usr/local/bin/php ).您使用的所有安装程序都不会覆盖 Apple 的默认安装- 他们会选择创建自己的目录或使用/usr/local/bin/代替(因此 PHP 中断器将安装在/usr/local/bin/php )。 In other words, you almost certainly have multiple php 's ready to use right now.换句话说,您现在几乎可以肯定有多个php可供使用。 The next thing you need to do is tell bash (the default terminal/cmd on a Mac) to use the newly installed PHP interrupter.您需要做的下一件事是告诉bash (Mac 上的默认终端/cmd)使用新安装的 PHP 中断器。

When you run $ php on your command line, bash checks for an executable file on each of paths stored in the PATH environment variable.当您在命令行上运行$ php时,bash 会检查存储在PATH环境变量中的每个路径上的可执行文件。 Once it finds one, it decides that that executable is the one you're looking for and runs that program.一旦它找到一个,它决定了可执行文件是你正在寻找并运行该程序的一个。 As of now, it's finding Apple's PHP 5.5 before it finds your fresh install of PHP 7.0 - assuming it finds PHP 7.0 at all.到目前为止,它会在找到您全新安装的 PHP 7.0 之前找到 Apple 的 PHP 5.5 - 假设它找到了 PHP 7.0。

You can fix this by updating PATH to check wherever PHP 7 is installed first.您可以通过更新PATH以检查首先安装 PHP 7 的位置来解决此问题。 Instructions to do so can be found on SuperUser.StackExchange:可以在 SuperUser.StackExchange 上找到这样做的说明:

How should I set the PATH variable on my Mac so the Homebrew-installed tools are found?我应该如何在 Mac 上设置 PATH 变量以便找到 Homebrew 安装的工具?

To change php version in Ubuntu, try to use this comand要在 Ubuntu 中更改 php 版本,请尝试使用此命令

sudo update-alternatives --config php

and then select version what you need然后选择你需要的版本

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

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