如何向 MAMP 添加其他 PHP 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16783558/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:41:52  来源:igfitidea点击:

How can I add additional PHP versions to MAMP

phpmacosmamp

提问by LiveSource

The current version of MAMP that I have only has php 5.2.17 and 5.4.4. I need 5.3.X. Is there a way to add additional versions that can be selected in the MAMP interfaces php preferences? This is for the free version of MAMP, not MAMP PRO.

我目前使用的 MAMP 版本只有 php 5.2.17 和 5.4.4。我需要 5.3.X。有没有办法添加可以在 MAMP 接口 php 首选项中选择的其他版本?这是针对 MAMP 的免费版本,而不是 MAMP PRO。

Thanks

谢谢

回答by LiveSource

Found a quick fix in the MAMP forums.

在 MAMP 论坛中找到了快速修复。

Basically it seems MAMP is only allowing 2 versions of PHP to show up. Quick fix, rename the folders you're not bothered about using, for me this meant adding an "X" to my /Applications/MAMP/bin/php/php5.4.10_X folder. Now 5.2.17 and 5.3.20 show up in the mamp prefs.

基本上,MAMP 似乎只允许出现 2 个版本的 PHP。快速修复,重命名您不想使用的文件夹,对我来说,这意味着在我的 /Applications/MAMP/bin/php/php5.4.10_X 文件夹中添加一个“X”。现在 5.2.17 和 5.3.20 出现在 mamp 首选项中。

Done!

完毕!

Edit - if the PHP version you require isn't in the PHP folder, you can download the version you require from http://www.mamp.info/en/downloads/

编辑 - 如果您需要的 PHP 版本不在 PHP 文件夹中,您可以从http://www.mamp.info/en/downloads/下载您需要的版本

Edit - MAMP don't seem to provide links to the alternative PHP versions on the download page any more. Use WayBackMachine https://web.archive.org/web/20180131074715/http://www.mamp.info/en/downloads/

编辑 - MAMP 似乎不再在下载页面上提供指向替代 PHP 版本的链接。使用 WayBackMachine https://web.archive.org/web/20180131074715/http://www.mamp.info/en/downloads/

回答by onedotover

If you need to be able to switch between more than two versions at a time, you can use the following to change the version of PHP manually.

如果您需要能够一次在两个以上版本之间切换,您可以使用以下命令手动更改 PHP 的版本。

MAMP automatically rewrites the following line in your /Applications/MAMP/conf/apache/httpd.conffile when it restarts based on the settings in preferences. You can comment out this line and add the second one to the end of your file:

当 MAMP根据首选项中的设置重新启动时,它会自动重写/Applications/MAMP/conf/apache/httpd.conf文件中的以下行。您可以注释掉这一行并将第二行添加到文件末尾:

# Comment this out just under all the modules loaded
# LoadModule php5_module        /Applications/MAMP/bin/php/php5.x.x/modules/libphp5.so

At the bottom of the httpd.conffile, you'll see where additional configurations are loaded from the extra folder. Add this to the bottom of the httpd.conf file

httpd.conf文件的底部,您将看到从额外文件夹加载其他配置的位置。将此添加到 httpd.conf 文件的底部

# PHP Version Change
Include /Applications/MAMP/conf/apache/extra/httpd-php.conf

Then create a new file here: /Applications/MAMP/conf/apache/extra/httpd-php.conf

然后在这里创建一个新文件:/Applications/MAMP/conf/apache/extra/httpd-php.conf

# Uncomment the version of PHP you want to run with MAMP
# LoadModule php5_module /Applications/MAMP/bin/php/php5.2.17/modules/libphp5.so
# LoadModule php5_module /Applications/MAMP/bin/php/php5.3.27/modules/libphp5.so
# LoadModule php5_module /Applications/MAMP/bin/php/php5.4.19/modules/libphp5.so
LoadModule php5_module /Applications/MAMP/bin/php/php5.5.3/modules/libphp5.so

After you have this setup, just uncomment the version of PHP you want to use and restart the servers!

完成此设置后,只需取消注释您要使用的 PHP 版本并重新启动服务器即可!

回答by Marianne

Maybe easy like this?

也许像这样容易?

Compiled binaries of the PHP interpreter can be found at http://www.mamp.info/en/downloads/index.html . Drop this downloaded folder into your /Applications/MAMP/bin/php! directory. Close and re-open your MAMP PRO application. Your new PHP version should now appear in the PHP drop down menu. MAMP PRO will only support PHP versions from the downloads page.

PHP 解释器的编译二进制文件可以在http://www.mamp.info/en/downloads/index.html找到。将此下载的文件夹放入您的 /Applications/MAMP/bin/php! 目录。关闭并重新打开您的 MAMP PRO 应用程序。您的新 PHP 版本现在应该出现在 PHP 下拉菜单中。MAMP PRO 将仅支持来自下载页面的 PHP 版本。

回答by ioCron

First stop the Server if its running. Go to "/Applications/MAMP/bin/", rename the PHP Version you don't need (MAMP is only allowed to use 2 PHP Versions), e.g. "_php5.2.17". Now MAMP will use the php versions that are left. Go to the MAMP Manager and then settings, then switch to the php version you need.

如果它正在运行,首先停止服务器。转到“/Applications/MAMP/bin/”,重命名不需要的 PHP 版本(MAMP 只允许使用 2 个 PHP 版本),例如“_php5.2.17”。现在 MAMP 将使用剩下的 php 版本。进入 MAMP 管理器,然后设置,然后切换到您需要的 php 版本。

One problem with this solution I encountered was the httpd process (took me a while to figure that out xD). If you have the httpd process running in the background, then the php switch won't work, until you stop those processes (sometimes MAMP has an awkward problem to stop the server, thats why this process can be still alive). Start your Activity Monitor on your Mac (Shortcut: Press Command+Space and type in activity...), go to the Search Function and type in "httpd", close all those processes. Now you should be able to switch your PHP Version with the MAMP Manager.

我遇到的这个解决方案的一个问题是 httpd 进程(我花了一段时间才弄清楚 xD)。如果你有 httpd 进程在后台运行,那么 php 开关将不起作用,直到你停止这些进程(有时 MAMP 有一个尴尬的问题来停止服务器,这就是为什么这个进程可以仍然活着)。在 Mac 上启动活动监视器(快捷方式:按 Command+Space 并输入活动...),转到搜索功能并输入“httpd”,关闭所有这些进程。现在您应该可以使用 MAMP 管理器切换您的 PHP 版本了。

回答by Krishnamoorthy Acharya

MAMP takes only two highest versions of the PHP in the following folder /Application/MAMP/bin/php

MAMP 在以下文件夹 /Application/MAMP/bin/php 中仅采用 PHP 的两个最高版本

As you can see here highest versions are 7.0.10 and 5.6.25 MAMP php Versions 7.0.10 and 5.6.25

如您所见,最高版本为 7.0.10 和 5.6.25 MAMP php 版本 7.0.10 和 5.6.25

Now 7.0.10 version is removed and as you can see highest two versions are 5.6.25 and 5.5.38 as shown in preferencesphp versions 5.6.25 and 5.5.38

现在 7.0.10 版本已被删除,您可以看到最高的两个版本是 5.6.25 和 5.5.38,如首选项所示php 版本 5.6.25 和 5.5.38

回答by Alex

The file /Applications/MAMP/bin/mamp/mamp.conf.json holds the MAMP configuration, look for the section:

文件 /Applications/MAMP/bin/mamp/mamp.conf.json 包含 MAMP 配置,查找部分:

{
  "name": "PHP",
  "version": "5.6.28, 7.0.20"
}

which lists the the php versions which will be displayed in the GUI, obviously you need to have downloaded the PHP version from the MAMP site first and placed it in /Applications/MAMP/bin/php for this to work.

它列出了将在 GUI 中显示的 php 版本,显然您需要先从 MAMP 站点下载 PHP 版本并将其放置在 /Applications/MAMP/bin/php 中才能正常工作。