简体   繁体   中英

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. I am using an Apple Silicon MacBook.

I am trying to follow this tutorial called " macOS 11.0 Big Sur Apache Setup: Multiple PHP Versions ".

So far so good, but now I am at this part where I have to install a PHP Switcher Script.

PHP Switcher Script We hard-coded Apache to use PHP 5.6, but we really want to be able to switch between versions. Luckily, some industrious individuals have already done the hard work for us and written a very handy little PHP switcher script.

This is the piece of code I installed to get the sphp function I need.

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. I even made appropriate changes in the httpd.conf and the sphp file to change the usr/local to opt/homebrew locations.

What happens now is after typing the sphp command, my terminal returns this, meaning it "works", but it doesn't.

 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.

I think this has something to do with the $apache_conf_path in the sphp file? 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. I am still stuck on the same PHP version I had earlier.

 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. It didn't change to 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

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\

On MacBook M1 apache and PHP 7.3 is pre-installed. All i do was modify httpd.conf and uncommented LoadModule php7_module libexec/apache2/libphp7.so . I think changing this line for other PHP versions may help as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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