skip to Main Content

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 [email protected]. 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 [email protected]
Switching your shell
Unlinking /opt/homebrew/Cellar/[email protected]/5.6.40... 25 symlinks removed.
Unlinking /opt/homebrew/Cellar/[email protected]/7.0.33... 0 symlinks removed.
Unlinking /opt/homebrew/Cellar/[email protected]/7.1.33... 0 symlinks removed.
Unlinking /opt/homebrew/Cellar/[email protected]/7.2.34... 0 symlinks removed.
Unlinking /opt/homebrew/Cellar/[email protected]/7.3.27... 0 symlinks removed.
Unlinking /opt/homebrew/Cellar/[email protected]/7.4.16... 0 symlinks removed.
Unlinking /opt/homebrew/Cellar/php/8.0.3... 0 symlinks removed.
Linking /opt/homebrew/Cellar/[email protected]/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/[email protected]/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/opt/homebrew/opt/[email protected]/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
[email protected]           stopped              
[email protected]           stopped              
[email protected]           stopped              
[email protected]           stopped              
[email protected]           stopped              
[email protected]           stopped  

The php indicated refers to [email protected]. It didn’t change to [email protected].

Any help would be appreciated, thanks!

2

Answers


  1. Chosen as BEST ANSWER

    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


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search