philcook / brew-php-switcher

Brew PHP switcher is a simple shell script to switch your apache and CLI quickly between major versions of PHP. If you support multiple products/projects that are built using either brand new or old legacy PHP functionality. For users of Homebrew (or brew for short) currently only.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem width brew-php-switcher and macOS Sierra

alisamii opened this issue · comments

Hi,

Ever since I upgraded to macOS Sierra, I am having a problem with brew-php-switcher.

When I issue the command bps (I set an alias for brew-php-switcher) I get the following error:

 alisamii@alisamii  /usr/local/etc/apache2/2.4  bps 70
Switching to php70
Switching your shell
Unlinking /usr/local/Cellar/php56/5.6.27_4... 0 symlinks removed
Unlinking /usr/local/Cellar/php70/7.0.12_5... 17 symlinks removed
Linking /usr/local/Cellar/php70/7.0.12_5... 17 symlinks created
You will need sudo power from now on
Switching your apache conf
Restarting apache
httpd: Syntax error on line 172 of /usr/local/etc/apache2/2.4/httpd.conf: Cannot load /usr/local/Cellar/php56/5.6.26_2/libexec/apache2/libphp5.so into server: dlopen(/usr/local/Cellar/php56/5.6.26_2/libexec/apache2/libphp5.so, 10): image not found
All done!

When I check line 172 of my https.conf file I see the following (lines 168-175):

LoadModule rewrite_module libexec/apache2/mod_rewrite.so
#LoadModule php5_module libexec/apache2/libphp5.so

LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so

#LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so

LoadModule hfs_apple_module libexec/apache2/mod_hfs_apple.so

When I check the location of libphp7.so I see it is there:

 alisamii@alisamii  /usr/local/etc/apache2/2.4  ls -l /usr/local/opt/php70/libexec/apache2/
total 11268
-rwxr-xr-x 1 alisamii admin 11537132 Oct 25 17:39 libphp7.so

and same thing for libphp5.so

 alisamii@alisamii  /usr/local/etc/apache2/2.4  ls -l /usr/local/opt/php56/libexec/apache2/
total 11100
-rwxr-xr-x 1 alisamii admin 11362692 Oct 25 17:24 libphp5.so

How do I solve this issue?

Hmmm...it also looks like bps thinks I am using Homebrew apache2, which I am not. I am using apple's built-in apache2.

@alisamii yes this looks like a big issue, I too have upgraded and notice things have changed! I will mark this as a bug.

FYI I am without an internet connection outside of work currently but this should be resolved soon and will be then able to update this project.

Any update on this big issue?

@alisamii The php formulas all seem to have removed the libexec modules by default. When installing a php version with the option --with-apache a new apache gets installed and linked by brew. With brew unlink httpd24 we can use the built-in apache again. This has to be done everytime we install a new php version. But maybe someone wants to use the Homebrew apache, so I would recommend getting the path to the httpd.conf file dynamically:

replacing line 27:
apache_conf_path="/etc/apache2/httpd.conf"
with:
apache_conf_path=$(apachectl -V | grep "SERVER_CONFIG_FILE") | cut -d '"' -f 2

This will output: /etc/apache2/httpd.conf or /usr/local/etc/apache2/2.4/httpd.conf (for Homebrew apache)

No update as yet, very busy in personal life at the moment. Hoping to pick the project in the new year.

@oncode when you refer to line 27 in what file are you referring?

I am finding that this issue is plaguing me in multiple ways. First, when I switch php versions using brew-php-switcher XX it appears to link/unlink various things, but regardless what I do, on the cli, when I issue the command

When I switch to PHP 70, this is what I get:

brew-php-switcher 70
Switching to php70
Switching your shell
Unlinking /usr/local/Cellar/php56/5.6.29_5... 17 symlinks removed
Unlinking /usr/local/Cellar/php70/7.0.14_7... 0 symlinks removed
Linking /usr/local/Cellar/php70/7.0.14_7... 17 symlinks created
You will need sudo power from now on
Password:
Switching your apache conf
Restarting apache
httpd: Syntax error on line 172 of /usr/local/etc/apache2/2.4/httpd.conf: Cannot load /usr/local/Cellar/php56/5.6.27_4/libexec/apache2/libphp5.so into server: dlopen(/usr/local/Cellar/php56/5.6.27_4/libexec/apache2/libphp5.so, 10): image not found
All done!

So, I assume I'm using php70, including on the cli...but not so:

php -v
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/opt/php56-varnish/varnish.so' - dlopen(/usr/local/opt/php56-varnish/varnish.so, 9): image not found in Unknown on line 0
PHP 5.6.29 (cli) (built: Dec  9 2016 15:51:49)
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
    with Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans
which php
/usr/local/opt/php56/bin/php

So, despite supposedly switching, it isn't.

But, when I load phpinfo in the browser, it is the correct version

PHP Version 7.0.14

Any ideas?

BTW, it really doesn't make a difference for me anymore, because for reasons completely unrelated to this, tonight is the last night for me. I will be no more. But maybe your answer will help others who may be in my situation (regarding PHP, not regarding ending my life, that is a whole other can of worms).

# stop shipped apache and remove from autostart
sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

# install homebrew apache with port 80 enabled
brew install httpd24 --with-privileged-ports --with-http2
sudo brew services start httpd24

# brew install php56 --with-httpd24 && brew unlink php56
brew reinstall --build-from-source php56 --with-httpd24 && brew unlink php56
# brew install php70 --with-httpd24 && brew unlink php70
brew reinstall --build-from-source php70 --with-httpd24 && brew unlink php70

open -e /usr/local/etc/apache2/2.4/httpd.conf
#LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
#LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so

brew install brew-php-switcher
ln -s /usr/local/bin/brew-php-switcher /usr/local/bin/sphp
open -e /usr/local/Cellar/brew-php-switcher/1.6/bin/phpswitch.sh
# apache_conf_path="/etc/apache2/httpd.conf"
# apache_conf_path="/usr/local/etc/apache2/2.4/httpd.conf"
apache_conf_path=$(apachectl -V | grep "SERVER_CONFIG_FILE" | cut -d '"' -f 2)

sphp 56
php -v

sphp 70
php -v

@mikebranderhorst How would I integrate my setup of dnsmasq?

Currently, I have the following setup:

dnsmasq.conf File

address=/.dev/127.0.0.1

Virtual Host File

# Virtual Hosts
#
# Required modules: mod_log_config

<Directory "/Volumes/sites">
  Options Indexes MultiViews FollowSymLinks
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

<Virtualhost *:80>
  VirtualDocumentRoot "/Volumes/sites/home/public"
  ServerName home.dev
  UseCanonicalName Off
</Virtualhost>

<Virtualhost *:80>
  VirtualDocumentRoot "/Volumes/sites/clients/%1/public"
  ServerName sites.dev
  ServerAlias *.dev
  UseCanonicalName Off
</Virtualhost>

<Virtualhost *:80>
  VirtualDocumentRoot "/Volumes/sites/clients/%-7+/public"
  ServerName xip
  ServerAlias *.xip.io
  UseCanonicalName Off
</Virtualhost>

<Virtualhost *:80>
  VirtualDocumentRoot "/Volumes/sites/demo/%1/public"
  ServerName demo.dev
  ServerAlias *.dev
  UseCanonicalName Off
</Virtualhost>

<Virtualhost *:80>
  VirtualDocumentRoot "/Volumes/sites/demo/%-7+/public"
  ServerName xip
  ServerAlias *.xip.io
  UseCanonicalName Off
</Virtualhost>

@mikebranderhorst Did you see my question to you above?

@philcook Can we take a reference form this gist
this very nicely couple of line near Linking new modphp addon... in this gist. which work perfectly fine for me, but some how it wasn't work for me.

I tried to install apache 24 with brew, and get it's already installed and it's located on /usr/local/Cellar/httpd/2.4.27_4/ I'm unable to remove that version and reuse brew-php-switcher for example when I switch to php71 I try to restart apache but can't open localhost at all, which is not case with php56. On the other hand I can restart apache only with sudo /usr/sbin/apachectl start and restarting with sudo apachectl start did pretty much nothing expect showing up AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using vaske-mbp.local. Set the 'ServerName' directive globally to suppress this message httpd (pid 21859) already running any idea what I did wrong? or what I should do to make running apache with php7?

I get this:

bash-4.4$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
/System/Library/LaunchDaemons/org.apache.httpd.plist: Could not find specified service
bash-4.4$ brew install httpd24 --with-privileged-ports --with-http2
==> Installing dependencies for httpd: apr, apr-util, c-ares, libev, jansson, boost, jemalloc, nghttp2
==> Installing httpd dependency: apr
==> Downloading https://homebrew.bintray.com/bottles/apr-1.6.3.sierra.bottle.tar.gz

curl: (6) Could not resolve host: homebrew.bintray.com
Error: Failed to download resource "apr"
Download failed: https://homebrew.bintray.com/bottles/apr-1.6.3.sierra.bottle.tar.gz
Warning: Bottle installation failed: building from source.
==> Downloading https://www.apache.org/dyn/closer.cgi?path=apr/apr-1.6.3.tar.bz2
Error: Failed to download resource "apr"
Download failed: Couldn't determine mirror, try again later.

I was blocked by my corporate LAN from upgrading to High Sierra, but if or once I'm added to a Beta testing group, I will be able to and I can ditch this entire mess.