简体   繁体   English

Apache 和 PHP 在 M1 MacBook 上设置

[英]Apache and PHP set up on M1 MacBook

I apologize for the lengthy question, I am just trying to get all the information out here in case it is helpful in getting an answer.对于这个冗长的问题,我深表歉意,我只是想在这里获取所有信息,以防有助于获得答案。 This is my first time setting up Apache and PHP.这是我第一次设置 Apache 和 PHP。 I am using an Apple Silicon MacBook.我正在使用 Apple Silicon MacBook。

I am trying to follow this tutorial called " macOS 11.0 Big Sur Apache Setup: Multiple PHP Versions ".我正在尝试遵循名为“ macOS 11.0 Big Sur Apache 设置:多个 PHP 版本”的教程。

So far so good, but now I am at this part where I have to install a PHP Switcher Script.到目前为止一切顺利,但现在我必须安装 PHP 切换器脚本。

PHP Switcher Script We hard-coded Apache to use PHP 5.6, but we really want to be able to switch between versions. PHP 切换器脚本 我们硬编码 Apache 以使用 PHP 5.6,但我们真的希望能够在版本之间切换。 Luckily, some industrious individuals have already done the hard work for us and written a very handy little PHP switcher script.幸运的是,一些勤奋的人已经为我们完成了艰苦的工作,并编写了一个非常方便的小 PHP 切换器脚本。

This is the piece of code I installed to get the sphp function I need. 这是我为获取我需要的 sphp function 而安装的一段代码

What's supposed to happen is, if I type sphp 5.6 into my Terminal, my PHP version should change to said version, in this case PHP@5.6.应该发生的是,如果我在终端中键入sphp 5.6 ,我的 PHP 版本应该更改为上述版本,在这种情况下为 PHP@5.6。 I even made appropriate changes in the httpd.conf and the sphp file to change the usr/local to opt/homebrew locations.我什至在 httpd.conf 和 sphp 文件中进行了适当的更改,以将 usr/local 更改为 opt/homebrew 位置。

What happens now is after typing the sphp command, my terminal returns this, meaning it "works", but it doesn't.现在发生的事情是在输入 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!

It works in the sense that the sphp command does something, but it doesn't actually change the PHP version that is being used.它的工作原理是 sphp 命令做了一些事情,但它实际上并没有改变正在使用的 PHP 版本。

I think this has something to do with the $apache_conf_path in the sphp file?我认为这与 sphp 文件中的$apache_conf_path有关系吗? As I said, I already changed it from usr/local to opt/homebrew, but for some reason when I type brew services , the change doesn't happen.正如我所说,我已经将它从 usr/local 更改为 opt/homebrew,但由于某种原因,当我键入brew services时,更改不会发生。 I am still stuck on the same PHP version I had earlier.我仍然停留在我之前使用的相同 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

The php indicated refers to PHP@8.0.指示的php是指 PHP@8.0。 It didn't change to PHP@5.6.它没有更改为 PHP@5.6。

Any help would be appreciated, thanks!任何帮助将不胜感激,谢谢!

I found the answer to my question in the comment section of the repository here: https://gist.github.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2我在这里的存储库的评论部分找到了我的问题的答案: https://gist.github.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2

Comment from: thomasisberg评论来自:托马斯伯格

Hi: Works great.嗨:效果很好。 But I had to change this line.但我不得不改变这条线。 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\ 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\

On MacBook M1 apache and PHP 7.3 is pre-installed.在 MacBook M1 上,apache 和 PHP 7.3 已预装。 All i do was modify httpd.conf and uncommented LoadModule php7_module libexec/apache2/libphp7.so .我所做的只是修改 httpd.conf 并取消注释LoadModule php7_module libexec/apache2/libphp7.so I think changing this line for other PHP versions may help as well.我认为将这条线更改为其他 PHP 版本也可能有所帮助。

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

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