Apache 和 PHP 在 M1 MacBook 上设置

时间:2021-04-13 15:30:10

标签: php apache apple-m1

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

我正在尝试学习名为“macOS 11.0 Big Sur Apache Setup: Multiple PHP Versions”的教程。

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

<块引用>

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

This is the piece of code 我安装以获得我需要的 sphp 函数。

应该发生的是,如果我在终端中输入 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。

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

2 个答案:

答案 0 :(得分:0)

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

评论来自:托马西斯伯格

<块引用>

嗨!效果很好!但我不得不改变这一行: sudo sed -i.bak "/$native_osx_php_apache_module/a\ 因为安装了 Homebrew 的 Apache conf中没有php模块。 (如果确实如此,它可能不会 位于 libexec/apache2/)。相反,我使用了: sudo sed -i.bak "/LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so/a\

答案 1 :(得分:0)

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