Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused how to switch PHP version #28102

Closed
6 tasks done
brendanfalkowski opened this issue May 22, 2018 · 4 comments
Closed
6 tasks done

Confused how to switch PHP version #28102

brendanfalkowski opened this issue May 22, 2018 · 4 comments
Labels
outdated PR was locked due to age

Comments

@brendanfalkowski
Copy link

brendanfalkowski commented May 22, 2018

  • are reporting a bug others will be able to reproduce and not asking a question. If you're not sure or want to ask a question do so on our Discourse: https://discourse.brew.sh
  • have a problem with brew install (or upgrade, reinstall) a single, official formula (not cask)? If it's a general brew problem please file this issue at Homebrew/brew: https://github.com/Homebrew/brew/issues/new/choose. If it's a brew cask problem please file this issue at https://github.com/caskroom/homebrew-cask/issues/new/choose. If it's a tap (e.g. Homebrew/homebrew-php) problem please file this issue at the tap.
  • ran brew update and can still reproduce the problem?
  • ran brew doctor, fixed all issues and can still reproduce the problem?
  • ran brew gist-logs <formula> (where <formula> is the name of the formula that failed) and included the output link?
  • if brew gist-logs didn't work: ran brew config and brew doctor and included their output with your issue?

What you were trying to do (and why)

Switch my PHP version from 7.1 to 5.6, so I could run indexer.php from the command line in a Magento 1 project.

What happened (include command output)

Note: this is after realizing Brew 1.6 changed a bunch of PHP things, and getting everything up to date.

$ brew switch php@5.6
Cleaning /usr/local/Cellar/php@5.6/5.6.36
Opt link created for /usr/local/Cellar/php@5.6/5.6.36
$ php -v
PHP 7.1.14 (cli) (built: Feb  7 2018 18:33:30) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
$ which php
/usr/bin/php
$ echo PATH
/Users/brendan/.composer/vendor/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Not sure where this leaves me, but it feels like a PATH problem and something that brew used to solve automatically.

What you expected to happen

My terminal should use PHP 5.6 after switching.

What I tried

Background: I'm a frontend developer not a sysadmin. I installed Homebrew 6 months ago because Composer wouldn't work without the php71-gmp package.

I always try to document my self-help here:

Things I read about recent brew and PHP changes:

I read and experimented for two hours, but I'm stuck. I ran through all the commands I could find to update/purge/clean my system:

brew update
brew upgrade
brew prune
brew doctor

All systems go from that end. Just lost on what brew did before, that I'm missing now.

Extra info

Output of brew list | grep php:

php@5.6
php@7.1

Output of brew config:

HOMEBREW_VERSION: 1.6.4
ORIGIN: https://github.com/Homebrew/brew
HEAD: f904017d721fa1efb2b9d61ca78512c07538ba7c
Last commit: 12 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 05fc7082623f947855460351999a07df74221c53
Core tap last commit: 54 minutes ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_DEV_CMD_RUN: 1
CPU: octa-core 64-bit haswell
Homebrew Ruby: 2.3.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Clang: 9.1 build 902
Git: 2.6.4 => /usr/local/bin/git
Curl: 7.54.0 => /usr/bin/curl
Java: N/A
macOS: 10.13.4-x86_64
CLT: 9.3.0.0.1.1521514116
Xcode: N/A
XQuartz: N/A
@ilovezfs
Copy link
Contributor

Quoting from the caveats that are printed upon installation:

This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/php@5.6/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/php@5.6/sbin:$PATH"' >> ~/.bash_profile

Thanks for filling out the template!

@brendanfalkowski
Copy link
Author

@ilovezfs — Thanks! I think I missed that in the logs. I edited my shell profile:

nano ~/.zshrc

And added these lines for both:

# From "brew" php@5.6
#export PATH="/usr/local/opt/php@5.6/bin:$PATH"
#export PATH="/usr/local/opt/php@5.6/sbin:$PATH"

# From "brew" php@7.1
export PATH="/usr/local/opt/php@7.1/bin:$PATH"
export PATH="/usr/local/opt/php@7.1/sbin:$PATH"

Getting an error though:

Running which php works now:

/usr/local/opt/php@7.1/bin/php

But running php -v returns a warning:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/opt/php71-gmp/gmp.so' - dlopen(/usr/local/opt/php71-gmp/gmp.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php71-gmp/gmp.so' - dlopen(/usr/local/opt/php71-gmp/gmp.so, 9): image not found in Unknown on line 0
PHP 7.1.17 (cli) (built: May 21 2018 22:46:54) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.17, Copyright (c) 1999-2018, by Zend Technologies

I thought the GMP extension was now bundled with php@7.1? I tried to install it the old way, but now it doesn't exist.

brew install php71-gmp

I found this issue which recommends re-installing from source, so I tried that:

brew reinstall --build-from-source php@5.6
brew reinstall --build-from-source php@7.1

But I still get the warnings when running php -v. Not sure if GMP is included or linked or not?

@ilovezfs
Copy link
Contributor

You need to clear out the old ini files from the config directories.

@brendanfalkowski
Copy link
Author

Thanks! I never would have guessed that on my own. Googled with that info, and found some guides that actually explain the whole thing.

@lock lock bot added the outdated PR was locked due to age label Jun 22, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jun 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

No branches or pull requests

2 participants