繁体   English   中英

Apache 和 PHP 在 M1 MacBook 上设置

[英]Apache and PHP set up on M1 MacBook

对于这个冗长的问题,我深表歉意,我只是想在这里获取所有信息,以防有助于获得答案。 这是我第一次设置 Apache 和 PHP。 我正在使用 Apple Silicon MacBook。

我正在尝试遵循名为“ macOS 11.0 Big Sur Apache 设置:多个 PHP 版本”的教程。

到目前为止一切顺利,但现在我必须安装 PHP 切换器脚本。

PHP 切换器脚本 我们硬编码 Apache 以使用 PHP 5.6,但我们真的希望能够在版本之间切换。 幸运的是,一些勤奋的人已经为我们完成了艰苦的工作,并编写了一个非常方便的小 PHP 切换器脚本。

这是我为获取我需要的 sphp function 而安装的一段代码

应该发生的是,如果我在终端中键入sphp 5.6 ,我的 PHP 版本应该更改为上述版本,在这种情况下为 PHP@5.6。 我什至在 httpd.conf 和 sphp 文件中进行了适当的更改,以将 usr/local 更改为 opt/homebrew 位置。

现在发生的事情是在输入 sphp 命令后,我的终端返回这个,这意味着它“工作”,但它没有。

 francisgomez@192 ~ % sphp 5.6 Switching to php@5.6 Switching your shell Unlinking /opt/homebrew/Cellar/php@5.6/5.6.40... 25 symlinks removed. Unlinking /opt/homebrew/Cellar/php@7.0/7.0.33... 0 symlinks removed. Unlinking /opt/homebrew/Cellar/php@7.1/7.1.33... 0 symlinks removed. Unlinking /opt/homebrew/Cellar/php@7.2/7.2.34... 0 symlinks removed. Unlinking /opt/homebrew/Cellar/php@7.3/7.3.27... 0 symlinks removed. Unlinking /opt/homebrew/Cellar/php@7.4/7.4.16... 0 symlinks removed. Unlinking /opt/homebrew/Cellar/php/8.0.3... 0 symlinks removed. Linking /opt/homebrew/Cellar/php@5.6/5.6.40... 25 symlinks created. If you need to have this software first in your PATH instead consider running: echo 'export PATH="/opt/homebrew/opt/php@5.6/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/opt/homebrew/opt/php@5.6/sbin:$PATH"' >> ~/.zshrc Switching your apache conf Restarting apache Stopping `httpd`... (might take a while) ==> Successfully stopped `httpd` (label: homebrew.mxcl.httpd) ==> Successfully started `httpd` (label: homebrew.mxcl.httpd) PHP 5.6.40 (cli) (built: Feb 28 2021 06:37:47) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies All done!

它的工作原理是 sphp 命令做了一些事情,但它实际上并没有改变正在使用的 PHP 版本。

我认为这与 sphp 文件中的$apache_conf_path有关系吗? 正如我所说,我已经将它从 usr/local 更改为 opt/homebrew,但由于某种原因,当我键入brew services时,更改不会发生。 我仍然停留在我之前使用的相同 PHP 版本上。

 francisgomez@192 ~ % brew services Name Status User Plist httpd started francisgomez /Users/francisgomez/Library/LaunchAgents/homebrew.mxcl.httpd.plist mongodb-community started francisgomez /Users/francisgomez/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist php started francisgomez /Users/francisgomez/Library/LaunchAgents/homebrew.mxcl.php.plist php@5.6 stopped php@7.0 stopped php@7.1 stopped php@7.2 stopped php@7.3 stopped php@7.4 stopped

指示的php是指 PHP@8.0。 它没有更改为 PHP@5.6。

任何帮助将不胜感激,谢谢!

我在这里的存储库的评论部分找到了我的问题的答案: https://gist.github.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2

评论来自:托马斯伯格

嗨:效果很好。 但我不得不改变这条线。 sudo sed -i,bak "/$native_osx_php_apache_module/a\ since Homebrew's Apache installed without a php module in the conf. (And if it did: it probably wouldn't be located at libexec/apache2/). Instead I used. sudo sed -i.bak "/LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so/a\

在 MacBook M1 上,apache 和 PHP 7.3 已预装。 我所做的只是修改 httpd.conf 并取消注释LoadModule php7_module libexec/apache2/libphp7.so 我认为将这条线更改为其他 PHP 版本也可能有所帮助。

暂无
暂无

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

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