简体   繁体   English

OSX Sierra-如何安装PHP7,并在终端中将5.6保留为默认值

[英]OSX Sierra - How to Install PHP7 and leave 5.6 as default in Terminal

short question - how to install php7.1 on OS X Sierra and keep 5.6 as default. 简短的问题-如何在OS X Sierra上安装php7.1并保持5.6为默认值。 I only want to run php 7.1 in terminal using php7 - and when using php the original 5.6 should be used ... 我只想使用php7在终端中运行php 7.1-使用php时应使用原始5.6 ...

thanx in advance tom 谢谢汤姆

There are a number of ways to achieve this. 有多种方法可以实现此目的。 I would install PHPBrew , since that allows you install as many PHP versions as you want without touching the system's PHP version. 我将安装PHPBrew ,因为这样您可以安装任意数量的 PHP版本,而无需接触系统的PHP版本。

I would also install Homebrew as it's likely there will be dependencies you need to resolve with specific extensions. 我还将安装Homebrew ,因为可能需要通过特定扩展来解决依赖项。

Another option would be to install PHP7 via Homebrew and alias it to php7. 另一个选择是通过Homebrew安装PHP7,并将其别名为php7。 Or you could compile it from source. 或者,您可以从源代码编译它。 However, if you plan on having one or more PHP versions readily available alongside the system version then PHPBrew is probably the most flexible option. 但是,如果您计划在系统版本旁边立即提供一个或多个PHP版本,则PHPBrew可能是最灵活的选择。

Install PHP 5.6: 安装PHP 5.6:

brew install php56

Install PHP 7.0: 安装PHP 7.0:

php70

Switch to php5.6 in terminal: 在终端中切换到php5.6:

brew unlink php70
brew link php56

Switch to php7.0 in terminal: 在终端中切换到php7.0:

brew unlink php56
brew link php70

Source: Switching PHP version on mac with homebrew 来源: 使用自制软件在Mac上切换PHP版本

maybe someone other is searching for a very clean solution too - here is what finally worked for me perfectly. 也许其他人也在寻找一个非常干净的解决方案-这就是最终对我来说完美的解决方案。 this is based on the hints and tips from matthew daly and surfer 190 - thanx again! 这是基于Matthew daly和190冲浪者的提示和技巧-thanx!

takes just 5 minutes - here we go ... 仅需5分钟-我们开始...

first install xcode command line tools (just 160mb instead 4.5gb): 首先安装xcode命令行工具(仅160mb代替4.5gb):

xcode-select --install

then install homebrew: 然后安装自制软件:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

short test if anything up to here is fine: 简短测试,直到这里是否还可以:

brew doctor

install php 7.1: 安装php 7.1:

brew install php71

i found that some have problems with the above direct php install - this resolves these problems - and then try again the php install: 我发现上面的直接php安装有一些问题-解决了这些问题-然后重试php安装:

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php

make a symlink to the original php-binary that came with osx: 进行符号链接到osx随附的原始php-binary:

ln -s /usr/bin/php /usr/local/bin/php5

here is the result - now php 7.1 is the default php version - and using php5 will use the old php-binary that came with your osx preinstalled: 结果是-现在php 7.1是默认的php版本-使用php5将使用预先安装了osx的旧php-binary:

php -v
php5 -v

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

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