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

Cannot brew link --force [email protected] out of the box #25974

Closed
mmelvin0 opened this issue Mar 30, 2018 · 19 comments
Closed

Cannot brew link --force [email protected] out of the box #25974

mmelvin0 opened this issue Mar 30, 2018 · 19 comments
Labels
outdated PR was locked due to age php PHP use is a significant feature of the PR or issue

Comments

@mmelvin0
Copy link

mmelvin0 commented Mar 30, 2018

I have php56, php70, and php71 installed from the homebrew-php tap. This morning I updated php71 to [email protected] in core.

What I was doing previously was linking /usr/local/bin/php71 -> /usr/local/opt/php71/bin/php for all relevant PHP tools so I could access multiple versions of PHP simultaneously while also "brew linking" (usually 7.1) to have a "default PHP".

This worked wonderfully for me with the tiny exception that when upgrading I needed to do some brew link juggling, but the whole process seemed pretty idiot-proof to me.

Now with [email protected], I noticed that, as with all versioned formula, it is keg-only and requires brew link --force. This is OK, but, with the addition of PEAR, it seems the the install processes has pooped some files directly into /usr/local/share/pear that conflict with

Basically my issue is that brew link --force is not a viable option out of the box with the new [email protected] formula. I do NOT want to do $PATH arithmetic in my .bashrc. The brew link (--force) option is a far better match to my needs/

I read up on why PEAR was added by default to [email protected] and agree with the rationale as it gives more flexibility and is more defers to pear.php.net and pecl.php.net.

The PEAR directory structure at /usr/local/share/pear is a bit of a mess of mutable config vs. static files. A bit more care needs to be taken to ensure any files placed there don't conflict with the formula's installed files.

I'm not sure exactly how to solve this in a general way. For me personally, I use a minimum set of officially supported PHP extensions and I never use PEAR, so a --without-pear option would be ideal for me, but I realize there are tons of other use cases the makes difficult or impossible.

I can easily workaround this by moving /usr/local/share/pear out of the way, but if you aren't intimately familiar with the ancient horror that is PEAR, doing this might easily break your installation.

Let me know if you need more info. Basic steps to reproduce are:

  1. Have php71 installed and linked (without pear, which was the default for homebrew-php)
  2. brew upgrade
  3. brew link --force [email protected]
@SMillerDev
Copy link
Member

So if I understand correctly your request is to have the PEAR directory versioned?

@mmelvin0
Copy link
Author

I think it should be either fully versioned or fully not-versioned. I'm not sure which is best generally though.

As it stands now, it's half-and-half with some files showing up in both places.

@kabel
Copy link
Contributor

kabel commented Apr 2, 2018

A fully versioned PEAR repository seems unnecessary, but may come with a future pull request.

brew link --force should only be used on the version you want to exclusively have linked at /usr/local/bin. If you try to do that with multiple versions, you're gonna have a bad time. Along the same lines, the /usr/local/share/pear is the currently linked version of php. Only one can exist there at a time. All others live in their opt location /usr/local/opt/[email protected]/share/pear. Although the default system pear config we currently write for all versions points the pear binaries back to the currently linked version (see /usr/local/opt/[email protected]/bin/pear config-get php_dir system).

@black-snow
Copy link
Contributor

Why was PHP renamed and why is it keg-only? Can't find any documentation or discussion on that.
I, too, have multiple php versions installed and switch them with brew un/link or brew-php-switcher but now it's broken.

@SMillerDev
Copy link
Member

There has been a caveat and an issue announcing this in the php tap since January.
And it's homebrew policy to make older versions of software keg only so naturally php had to abide by that with the migration.

@k7y6t5
Copy link

k7y6t5 commented Apr 3, 2018

@mmelvin0 can you be more specific about this?

I can easily workaround this by moving /usr/local/share/pear out of the way...

I'm just trying to get [email protected] working and am seeing the same error when running $ brew link --force [email protected]

On a related note, is this the recommended way to use Homebrew's PHP instead of the one that ships with MacOS? Running $ which php still outputs /usr/bin/php and I would expect it to show /usr/local/bin/php.

@SMillerDev
Copy link
Member

which returns only the first instance of an executable in your path so this is something in your setup then.

@k7y6t5
Copy link

k7y6t5 commented Apr 3, 2018

Well, there's no PHP alias in /usr/local/bin, so I guess I need to get [email protected] linked? If so, I'll need to figure this out first:

devteams-iMac:~ devteam$ brew link --force [email protected]
Linking /usr/local/Cellar/[email protected]/7.1.16... 
Error: Could not symlink share/pear/.channels/.alias/pear.txt
Target /usr/local/share/pear/.channels/.alias/pear.txt
already exists. You may want to remove it:
  rm '/usr/local/share/pear/.channels/.alias/pear.txt'

To force the link and overwrite all conflicting files:
  brew link --overwrite [email protected]

To list all files that would be deleted:
  brew link --overwrite --dry-run [email protected]

@SMillerDev
Copy link
Member

You can't have 2 php versions linked at the same time, you'll have to unlink your current one first.

@k7y6t5
Copy link

k7y6t5 commented Apr 3, 2018

I do not have a currently linked version. [email protected] is the first that I'm trying.

@SMillerDev
Copy link
Member

can you do brew list | grep php?

@k7y6t5
Copy link

k7y6t5 commented Apr 3, 2018

devteams-iMac:~ devteam$ brew list | grep php
[email protected]
devteams-iMac:~ devteam$ 

@SMillerDev
Copy link
Member

curious, I guess I'd just copy the offending file to a safe place and remove the original then.

@k7y6t5
Copy link

k7y6t5 commented Apr 3, 2018

Looks to be many more than just the pear.txt file:

devteams-iMac:~ devteam$ brew link --force --overwrite --dry-run [email protected]
Would remove:
/usr/local/share/pear/.channels/.alias/pecl.txt
/usr/local/share/pear/.channels/.alias/phpdocs.txt
/usr/local/share/pear/.channels/__uri.reg
/usr/local/share/pear/.channels/doc.php.net.reg
/usr/local/share/pear/.channels/pear.php.net.reg
/usr/local/share/pear/.channels/pecl.php.net.reg
/usr/local/share/pear/.depdb
/usr/local/share/pear/.depdblock
/usr/local/share/pear/.filemap
/usr/local/share/pear/.lock
/usr/local/lib/httpd/build/config.nice
/usr/local/lib/httpd/build/config_vars.mk
/usr/local/lib/httpd/build/instdso.sh
/usr/local/lib/httpd/build/library.mk
/usr/local/lib/httpd/build/ltlib.mk
/usr/local/lib/httpd/build/mkdir.sh
/usr/local/lib/httpd/build/program.mk
/usr/local/lib/httpd/build/rules.mk
/usr/local/lib/httpd/build/special.mk
/usr/local/lib/httpd/modules/httpd.exp
/usr/local/lib/httpd/modules/mod_access_compat.so
/usr/local/lib/httpd/modules/mod_actions.so
/usr/local/lib/httpd/modules/mod_alias.so
/usr/local/lib/httpd/modules/mod_allowmethods.so
/usr/local/lib/httpd/modules/mod_asis.so
/usr/local/lib/httpd/modules/mod_auth_basic.so
/usr/local/lib/httpd/modules/mod_auth_digest.so
/usr/local/lib/httpd/modules/mod_auth_form.so
/usr/local/lib/httpd/modules/mod_authn_anon.so
/usr/local/lib/httpd/modules/mod_authn_core.so
/usr/local/lib/httpd/modules/mod_authn_dbd.so
/usr/local/lib/httpd/modules/mod_authn_dbm.so
/usr/local/lib/httpd/modules/mod_authn_file.so
/usr/local/lib/httpd/modules/mod_authn_socache.so
/usr/local/lib/httpd/modules/mod_authnz_fcgi.so
/usr/local/lib/httpd/modules/mod_authz_core.so
/usr/local/lib/httpd/modules/mod_authz_dbd.so
/usr/local/lib/httpd/modules/mod_authz_dbm.so
/usr/local/lib/httpd/modules/mod_authz_groupfile.so
/usr/local/lib/httpd/modules/mod_authz_host.so
/usr/local/lib/httpd/modules/mod_authz_owner.so
/usr/local/lib/httpd/modules/mod_authz_user.so
/usr/local/lib/httpd/modules/mod_autoindex.so
/usr/local/lib/httpd/modules/mod_brotli.so
/usr/local/lib/httpd/modules/mod_buffer.so
/usr/local/lib/httpd/modules/mod_cache.so
/usr/local/lib/httpd/modules/mod_cache_disk.so
/usr/local/lib/httpd/modules/mod_cache_socache.so
/usr/local/lib/httpd/modules/mod_cgi.so
/usr/local/lib/httpd/modules/mod_cgid.so
/usr/local/lib/httpd/modules/mod_charset_lite.so
/usr/local/lib/httpd/modules/mod_data.so
/usr/local/lib/httpd/modules/mod_dav.so
/usr/local/lib/httpd/modules/mod_dav_fs.so
/usr/local/lib/httpd/modules/mod_dav_lock.so
/usr/local/lib/httpd/modules/mod_dbd.so
/usr/local/lib/httpd/modules/mod_deflate.so
/usr/local/lib/httpd/modules/mod_dialup.so
/usr/local/lib/httpd/modules/mod_dir.so
/usr/local/lib/httpd/modules/mod_dumpio.so
/usr/local/lib/httpd/modules/mod_echo.so
/usr/local/lib/httpd/modules/mod_env.so
/usr/local/lib/httpd/modules/mod_expires.so
/usr/local/lib/httpd/modules/mod_ext_filter.so
/usr/local/lib/httpd/modules/mod_file_cache.so
/usr/local/lib/httpd/modules/mod_filter.so
/usr/local/lib/httpd/modules/mod_headers.so
/usr/local/lib/httpd/modules/mod_heartbeat.so
/usr/local/lib/httpd/modules/mod_heartmonitor.so
/usr/local/lib/httpd/modules/mod_http2.so
/usr/local/lib/httpd/modules/mod_include.so
/usr/local/lib/httpd/modules/mod_info.so
/usr/local/lib/httpd/modules/mod_lbmethod_bybusyness.so
/usr/local/lib/httpd/modules/mod_lbmethod_byrequests.so
/usr/local/lib/httpd/modules/mod_lbmethod_bytraffic.so
/usr/local/lib/httpd/modules/mod_lbmethod_heartbeat.so
/usr/local/lib/httpd/modules/mod_log_config.so
/usr/local/lib/httpd/modules/mod_log_debug.so
/usr/local/lib/httpd/modules/mod_log_forensic.so
/usr/local/lib/httpd/modules/mod_logio.so
/usr/local/lib/httpd/modules/mod_macro.so
/usr/local/lib/httpd/modules/mod_md.so
/usr/local/lib/httpd/modules/mod_mime.so
/usr/local/lib/httpd/modules/mod_mime_magic.so
/usr/local/lib/httpd/modules/mod_mpm_event.so
/usr/local/lib/httpd/modules/mod_mpm_prefork.so
/usr/local/lib/httpd/modules/mod_mpm_worker.so
/usr/local/lib/httpd/modules/mod_negotiation.so
/usr/local/lib/httpd/modules/mod_proxy.so
/usr/local/lib/httpd/modules/mod_proxy_ajp.so
/usr/local/lib/httpd/modules/mod_proxy_balancer.so
/usr/local/lib/httpd/modules/mod_proxy_connect.so
/usr/local/lib/httpd/modules/mod_proxy_express.so
/usr/local/lib/httpd/modules/mod_proxy_fcgi.so
/usr/local/lib/httpd/modules/mod_proxy_fdpass.so
/usr/local/lib/httpd/modules/mod_proxy_ftp.so
/usr/local/lib/httpd/modules/mod_proxy_hcheck.so
/usr/local/lib/httpd/modules/mod_proxy_html.so
/usr/local/lib/httpd/modules/mod_proxy_http.so
/usr/local/lib/httpd/modules/mod_proxy_scgi.so
/usr/local/lib/httpd/modules/mod_proxy_uwsgi.so
/usr/local/lib/httpd/modules/mod_proxy_wstunnel.so
/usr/local/lib/httpd/modules/mod_ratelimit.so
/usr/local/lib/httpd/modules/mod_reflector.so
/usr/local/lib/httpd/modules/mod_remoteip.so
/usr/local/lib/httpd/modules/mod_reqtimeout.so
/usr/local/lib/httpd/modules/mod_request.so
/usr/local/lib/httpd/modules/mod_rewrite.so
/usr/local/lib/httpd/modules/mod_sed.so
/usr/local/lib/httpd/modules/mod_session.so
/usr/local/lib/httpd/modules/mod_session_cookie.so
/usr/local/lib/httpd/modules/mod_session_crypto.so
/usr/local/lib/httpd/modules/mod_session_dbd.so
/usr/local/lib/httpd/modules/mod_setenvif.so
/usr/local/lib/httpd/modules/mod_slotmem_plain.so
/usr/local/lib/httpd/modules/mod_slotmem_shm.so
/usr/local/lib/httpd/modules/mod_socache_dbm.so
/usr/local/lib/httpd/modules/mod_socache_memcache.so
/usr/local/lib/httpd/modules/mod_socache_shmcb.so
/usr/local/lib/httpd/modules/mod_speling.so
/usr/local/lib/httpd/modules/mod_ssl.so
/usr/local/lib/httpd/modules/mod_status.so
/usr/local/lib/httpd/modules/mod_substitute.so
/usr/local/lib/httpd/modules/mod_suexec.so
/usr/local/lib/httpd/modules/mod_unique_id.so
/usr/local/lib/httpd/modules/mod_unixd.so
/usr/local/lib/httpd/modules/mod_userdir.so
/usr/local/lib/httpd/modules/mod_usertrack.so
/usr/local/lib/httpd/modules/mod_version.so
/usr/local/lib/httpd/modules/mod_vhost_alias.so
/usr/local/lib/httpd/modules/mod_watchdog.so
/usr/local/lib/httpd/modules/mod_xml2enc.so

@k7y6t5
Copy link

k7y6t5 commented Apr 3, 2018

Ok I went ahead and ran $ brew link --force --overwrite [email protected] and then restarted Apache. The output of $which php now shows /usr/local/bin/php. I can also see the output of phpinfo() in a browser, so I guess this is fixed.

Thanks for your help, @SMillerDev. I'm going to try installing [email protected] and figuring out the switching process.

@kylemilloy
Copy link

kylemilloy commented Apr 3, 2018

Couldn't get this working with all that's suggested here but found another work around.

brew link regardless of forcing or overwriting refuses to put a reference to php into my local bin so I made a file where I can switch between different versions of PHP as needed. I use 5.6, 7.0 and 7.1 for various projects...edit as necessary for what you have installed

Create ~/.php-version and post in the following:

#export PATH="/usr/local/opt/[email protected]/bin:$PATH"
#export PATH="/usr/local/opt/[email protected]/sbin:$PATH"

#export PATH="/usr/local/opt/[email protected]/bin:$PATH"
#export PATH="/usr/local/opt/[email protected]/sbin:$PATH"

export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/sbin:$PATH"

Comment out all but the version of php you want active with hashes.

Edit ~/.bash_profile and add:

# PHP Version
source ~/.php-version

Reload the new config or open a new terminal window and confirm the switch is done with which php and php -v

I also had to remove all my configs for older installations as to not conflict with the new pecl module stuff so went into /usr/local/etc/php and cleared out all the ini files here.

@mmelvin0
Copy link
Author

mmelvin0 commented Apr 3, 2018

@subtlegusto
To be more specific, I don't use PEAR at all, so I just deleted /usr/local/share/pear entirely prior to linking [email protected]. If you do use PEAR or had an existing PEAR installation at that location, this may cause you pain. I'm unsure about the other files you were seeing conflicting though. My conflicts were only in the PEAR directory. A little scary that [email protected] would overwrite a whole bunch of httpd modules that aren't mod_php. However, I was upgrading and you were installing fresh.

@kabel
I have only ever been using brew link with a single version of PHP at a time. The other links I described were created manually so I could access php56 CLI as that name without mucking around with $PATH.

The fact that /usr/local/opt/[email protected]/bin/pear config-get php_dir system returns /usr/local/share/pear does NOT indicate that "the default system pear config we currently write for all versions points the pear binaries back to the currently linked version" because if [email protected] is NOT linked and you invoke its pear will still write stuff to /usr/local/share/pear. Since the formula is keg-only by default and the expectation is that it will NOT normally be linked, that results in conflicts when trying to link the single version of this formula.

Hence why I think the PEAR directory should be either entirely versioned and entirely unversioned. I'm leaning towards unversioned, since users likely would want to share PEAR libraries between versions and the PECL build directory is already versioned with the Zend ABI date, but I realize that it's a bit weird to install stuff directly into /usr/local/share especially for a keg-only formula.

@kabel
Copy link
Contributor

kabel commented Apr 4, 2018

I see the error in my thinking. Pear and pecl share a meta repo. Pull request to follow.

@ilovezfs ilovezfs added the php PHP use is a significant feature of the PR or issue label Apr 4, 2018
@ilovezfs
Copy link
Contributor

Closed via #26137. Thanks to @kabel

@lock lock bot added the outdated PR was locked due to age label May 12, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 12, 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 php PHP use is a significant feature of the PR or issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants