如何在 Mac OSX 上轻松切换 PHP 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34909101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I easily switch between PHP versions on Mac OSX?
提问by Xaver
I would like to test my application on PHP 5.3 up to PHP 7.0.
我想在 PHP 5.3 到 PHP 7.0 上测试我的应用程序。
Where and how can I install the versions and how can I switch them by running a small script?
我在哪里以及如何安装版本以及如何通过运行一个小脚本来切换它们?
回答by Xaver
I found this very good tutorialon how to install and switch php versions on OSX.
我发现这个关于如何在 OSX 上安装和切换 php 版本的非常好的教程。
I can switch the version like
我可以切换版本
$ sphp 7.0 => PHP 7.0
$ sphp 7.3 => PHP 7.3
$ sphp 7.4 => PHP 7.4
Exactly what I want!
正是我想要的!
回答by kris
Using brew
使用 brew
Show current version
显示当前版本
$ php -v
Change to different version
(eg. changing from 5.5.x to version 7.0.latest) :
更改为不同版本
(例如,从 5.5.x 更改为 7.0.latest 版本):
$ brew unlink php55
$ brew install php70
回答by Goke Obasa
If you have both versions of PHP installed, you can switch between versions using the link
and unlink
brew
commands.
如果您安装了两个版本的 PHP,则可以使用link
和unlink
brew
命令在版本之间切换。
For example, to switch between PHP 7.4 and PHP 7.3
例如,在 PHP 7.4 和 PHP 7.3 之间切换
brew unlink [email protected]
brew link [email protected]
PS: both versions of PHP have be installed for these commands to work.
PS:为了让这些命令可以工作,已经安装了两个版本的 PHP。
回答by Mark Setchell
If you install PHP with homebrew, you can switch between versions very easily. Say you want php56
to point to Version 5.6.17, you just do:
如果使用homebrew安装 PHP ,则可以非常轻松地在版本之间切换。假设您想php56
指向 5.6.17 版,您只需执行以下操作:
brew switch php56 5.6.17
回答by thai.hulk
i think unlink & link php versions are not enough because we are often using php with apache(httpd), so need to update httpd.conf after switch php version.
我认为 unlink & link php 版本是不够的,因为我们经常使用 php 和 apache(httpd),所以需要在切换 php 版本后更新 httpd.conf。
i have write shell script for disable/enable php_module
automatically inside httpd.conf
, look at line 46 to line 54 https://github.com/dangquangthai/switch-php-version-on-mac-sierra/blob/master/switch-php#L46
我在里面写了php_module
自动禁用/启用的 shell 脚本httpd.conf
,看看第 46 行到第 54 行https://github.com/dangquangthai/switch-php-version-on-mac-sierra/blob/master/switch-php#L46
Follow my steps:
按照我的步骤:
1) Check installed php versions by brew, for sure everything good
1) 通过 brew 检查已安装的 php 版本,确保一切正常
> brew list | grep php
#output
php56
php56-intl
php56-mcrypt
php71
php71-intl
php71-mcrypt
2) Run script
2)运行脚本
> switch-php 71 # or switch-php 56
#output
PHP version [71] found
Switching from [php56] to [php71] ...
Unlink php56 ... [OK] and Link php71 ... [OK]
Updating Apache2.4 Configuration /usr/local/etc/httpd/httpd.conf ... [OK]
Restarting Apache2.4 ... [OK]
PHP 7.1.11 (cli) (built: Nov 3 2017 08:48:02) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
3) Finally, when your got above message, check httpd.conf
, in my laptop:
3)最后,当您收到上述消息时,请httpd.conf
在我的笔记本电脑中检查:
vi /usr/local/etc/httpd/httpd.conf
You can see near by LoadModule lines
你可以看到附近的 LoadModule 线
LoadModule php7_module /usr/local/Cellar/php71/7.1.11_22/libexec/apache2/libphp7.so
#LoadModule php5_module /usr/local/Cellar/php56/5.6.32_8/libexec/apache2/libphp5.so
4) open httpd://localhost/info.php
4)打开httpd://localhost/info.php
i hope it helpful
我希望它有帮助