Coder Social home page Coder Social logo

philcook / brew-php-switcher Goto Github PK

View Code? Open in Web Editor NEW
951.0 21.0 89.0 73 KB

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.

License: MIT License

Shell 100.00%
homebrew php shell

brew-php-switcher's Introduction

Brew PHP Switcher CI

Brew PHP switcher is a simple script to switch your Apache and CLI configs quickly between major versions of PHP.

If you support multiple products/projects that are built using either brand new or old legacy PHP functionality and you find it a pain to change config files continually this will make the whole process just one command.

Caveats

For users of OSX only who have installed PHP via Homebrew and for PHP version 5.6, 7.0, 7.1, 7.2, 7.3, 7.4 and 8.0 only.

Your Apache config must have native osx PHP module commented out.

#LoadModule php5_module libexec/apache2/libphp5.so

Brew PHP Switcher will automatically add the Homebrew's PHP module location in the Apache config in the following format.

#LoadModule php5_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp5.so
#LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp8.so

Version

2.3

Installation

brew install brew-php-switcher

Where 5.6 exists, please replace with syntax of 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2 or 8.3 depending on which version is required.

brew-php-switcher 5.6

by default will switch apache config

Options

  • -s|-s=* Skips apache & valet config switch for i.e
# skip apache only
brew-php-switcher 5.6 -s

# skip valet only
brew-php-switcher 5.6 -s=valet

# skip valet & apache
brew-php-switcher 5.6 -s=valet,apache
  • -c=* switch a specific config for i.e
# switch valet config only
brew-php-switcher 5.6 -c=valet

# switch valet & apache config only
brew-php-switcher 5.6 -c=valet,apache

# switch apache config only
brew-php-switcher 5.6 -c=apache

License

MIT

brew-php-switcher's People

Contributors

andrew-miller-rakuten avatar binotaliu avatar bobbybouwmann avatar chancegarcia avatar chrisdeeming avatar cjwilburn avatar cmonard avatar dammy001 avatar danielcosta avatar danielruf avatar davemednick avatar devdetonator avatar galdiolo avatar ikari7789 avatar jamesrezo avatar oleg-andreyev avatar pgrimaud avatar philcook avatar rebelinblue avatar salkhwlani avatar sheldon avatar webflo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

brew-php-switcher's Issues

Switch to 8.2

Hello,

Could you release the last commit with the php8.2 release?

Thanks :D

Error: No available formula with the name "brew-php-switcher"

→ brew install brew-php-switcher
Error: No available formula with the name "brew-php-switcher"
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
  git -C "$(brew --repo homebrew/core)" fetch --unshallow

Error: No previously deleted formula found.
==> Searching for similarly named formulae...
==> Searching local taps...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.

Then I tried:

→ git -C "$(brew --repo homebrew/core)" fetch --unshallow
fatal: dumb http transport does not support shallow capabilities

bison: undefined method `uses_from_macos'

Warning: You are using macOS 10.15.
We do not provide support for this pre-release version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience, as you are running this pre-release version.

brew-php-switcher still shows either version in iTerm after switching

I have php v5.6, v7.3, and v7.4

When I switch either 7.3 or 7.4 and type php -v in iTerm, it still logs me the 5.6 even if phpinfo() logs me right. So, when I install laravel with laravel new my-app, it shows me error: This package requires php ^7.2 but your PHP version (5.6.40) does not satisfy that requirement.

please help

Have you tested with PHP v8

I know PHP v8 was just released, but I am eager to give it a whirl but I don’t want to have to spin up docker just to test PHP v8 (I would like to try it on a number of active PHP projects)

Problem width brew-php-switcher and macOS Sierra

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?

Fork for maintainability?

While I’ve been given contributor permissions, this repository requires at least one approval in order to merge PRs, so with the only other contributor being largely inactive, improvements by myself are basically impossible. I’d like to help support some of the issues reported here, but it’s almost impossible. Would the community support me forking this repository and updating the Brew formula accordingly to use the fork?

No available formula with the name "brew-php-switcher"

Hi, after this whole "homebrew-php" migration debacle, I can't install this formula.

Here is my output:

→ brew install brew-php-switcher
Error: No available formula with the name "brew-php-switcher"
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
  git -C "$(brew --repo homebrew/core)" fetch --unshallow

Error: No previously deleted formula found.
==> Searching for similarly named formulae...
==> Searching local taps...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.

Any ideas?

Support for [email protected]

It looks like this issue has been raised before via PR, but not as a proper issue. I'd like some support for PHP v7.2

Not compatible with brew installed Apache

This script modifies the config file at /private/etc/apache2/httpd.conf which is for the copy of Apache that ships with OS X.

If you install Apache with homebrew the config file is located at /usr/local/etc/apache2/2.4/httpd.conf

Maybe you could update the script to modify both files?

Why use homebrew Apache:

The latest macOS 10.12 Sierra comes with Apache 2.4 pre-installed, however, it is no longer a simple task to use this version with Homebrew because Apple has removed some required scripts in this release. However, the solution is to install Apache 2.4 via Homebrew and then configure it to run on the standard ports (80/443).
https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions

apache config does not change

Thanks for building this great brew package.

I have used it for switching between php 7.4 and php 8.1 in the terminal. It works great.

But it does not modify the apache httpd config file for the chosen php version.

I am on Mac (M1 Max).

Please advice.

Add a check for existence of the libexec modules

Hey, cool project! Thank you!

I just came across this once again so I figured I'll just add this as an idea for a new feature.
Depending on your setup you need to install php using e.g. brew install php70 --with-apache otherwise the module will just be missing :-)
I think it would be a nice feature if the switcher checked for the existence of the module and would output something like "Are you sure you installed php via homebrew using the --with-apache command line option?". If the module does not exist, I don't think that it should be possible to switch to that version :-)

Not working anymore after homebrew switched the core

→ brew-php-switcher 71 
Switching to php71
Switching your shell
Unlinking /usr/local/Cellar/[email protected]/5.6.36... 0 symlinks removed
Unlinking /usr/local/Cellar/[email protected]/7.1.17... 0 symlinks removed
Unlinking /usr/local/Cellar/php/7.2.5... 0 symlinks removed
Warning: [email protected] is keg-only and must be linked with --force
Note that doing so can interfere with building software.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/[email protected]/sbin:$PATH"' >> ~/.zshrc
You will need sudo power from now on
Switching your apache conf
Restarting apache
All done!


# phx at phx.local in ~ [15:07:53]
→ php --version
PHP 5.6.30 (cli) (built: Oct 29 2017 20:30:32)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

PHP 7.x support

Is there any plan to support PHP 7.x while it's still not stable?

Error restarting Brew Apache after Switching PHP Versions

I have a problem where I have PHP 5.6 and 7.1 installed along with the Brew httpd server, but only PHP 5.6 will allow the httpd server to start.

If I run brew-php-switcher -s 56 and manually swap the httpd.conf file to load PHP 56, apache starts and all is right with the world.

If I do the same with 71, apache will not start and I will see:
[mpm_prefork:notice] [pid 78837] AH00173: SIGHUP received. Attempting to restart
[core:notice] [pid 78837] AH00060: seg fault or similar nasty error detected in the parent process

in the error logs. Any further attempts to start apache manually through apachectl will not show anything new in the log file. The only difference between the httpd.conf files is:

LoadModule php5_module /usr/local/Cellar/php56/5.6.33_9/libexec/apache2/libphp5.so
vs
LoadModule php7_module /usr/local/Cellar/php71/7.1.14_25/libexec/apache2/libphp7.so

If I swap back to 56, apache starts just fine. I can manually run

brew unlink (56|71)
brew link (71|56)
cp httpd.conf.(71|56) httpd.conf
sudo apachectl restart

and get the same result. Any clues as to what might be wrong here?

Both php56 and php71 were installed with the --with-httpd flags
Now that I've installed the Brew apache server, the default High Sierra apache server has decided it doesn't want to run anymore.

apache not restarted

brew-php-switcher seems to stop apache just fine...
it just doesn't seem to restart it for me
I always have to sudo apachectl -k start after running brew-php-switcher

thoughts?

icu4c PHP dependency

I've been running PHP 5.6 (yes, I know it's way deprecated, but it's the version I must use for my day job)

brew install brew-php-switcher
This appears to have run brew update.. or at least updated my PHP 7.x install...
I believe this in turn updated a "icu4c" dependency

When running PHP 5.6 I now get:

php -v
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib
  Referenced from: /usr/local/bin/php
  Reason: image not found

here's the fix:
https://stackoverflow.com/a/56242725/1371433

However
if I now brew-php-switcher 7.3

php -v
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib
  Referenced from: /usr/local/bin/php
  Reason: image not found

PHP 5.6 requires icu4c 62.1 and PHP 7.3 requires icu4c 64.2
there seems to be no easy way to switch between the two..

supposedly brew switch icu4c 64.2 should work, but I get a "not in cellar" error

The only fix seems to be to reinstall icu4c

62.1: brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/575eb4bbef683551e19f329f60456b13a558132f/Formula/icu4c.rb
64.2: brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/icu4c.rb
(I'm not sure how to find the direct link for 64.2.. It's likely that link will point to a newer ver in the future)

Anyone know how to get brew-php-switcher to also switch/update this dependency?

Cannot switch to PHP @7.1

I am having issues on switching php @ 7.1 with brew-php-switcher, I have Mojave. Below is the output i get.

Your system is ready to brew.

brew-php-switcher 7.1

Switching to [email protected]
Switching your shell
Unlinking /usr/local/Cellar/[email protected]/7.1.24_2... 0 symlinks removed
Linking /usr/local/Cellar/[email protected]/7.1.24_2...
Error: Could not symlink bin/pear
Target /usr/local/bin/pear
is a symlink belonging to php. You can unlink it:
  brew unlink php

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]
You will need sudo power from now on
Switching your apache conf
Password:
Restarting apache
All done!```

``` php -v
PHP 7.2.12 (cli) (built: Nov 29 2018 00:54:39) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.12, Copyright (c) 1999-2018, by Zend Technologies```

Won't execute PHP scripts in PHP70

But PHP56 works fine.

Not sure what's going on. brew doctor is happy. php --ini shows:

Configuration File (php.ini) Path: /usr/local/etc/php/7.0
Loaded Configuration File:         /usr/local/etc/php/7.0/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.0/conf.d
Additional .ini files parsed:      /usr/local/etc/php/7.0/conf.d/ext-mcrypt.ini

But .php files themselves aren't executed and just show code in the browser. If I switch back to PHP56 they work fine.

Apache php module entries not added automatically

Hello,

Just installed this and noticed that as much as this script will comment out the necessary 'LoadModule' strings when swithcing PHP versions it doesnt seem to add new LoadModule lines.

I've noticed in this code there is a comment saying it will do this.. but it doesnt seem to be adding in a 'fresh': php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so for me. I had to add it manually so it could be automatically commented.

Nothing major but im guessing this is a bug, probably something to look into.

New release

Could you please create a new release including #5 to allow update of brew-php-switch formula on homebrew/homebrew-php?

Ports to Linux?

So this is working beautifully for us with MacOS, but we need it also for Linux. Has someone forked and adapted this for Ubuntu or RHEL yet?

Creating a file called 101300

brew-php-switcher is creating a file called 101300 whenever I run it

stephen at MacBook-Pro in ~/Desktop/tmp
$ ls                                                                                                                                                                                                                                 

stephen at MacBook-Pro in ~/Desktop/tmp
$ brew-php-switcher 7.2 -s                                                                                                                                                                                                           
Switching to [email protected]
Switching your shell
Unlinking /usr/local/Cellar/[email protected]/7.0.32_2... 0 symlinks removed
Unlinking /usr/local/Cellar/[email protected]/7.1.25... 25 symlinks removed
Unlinking /usr/local/Cellar/[email protected]/7.2.14... 0 symlinks removed
Unlinking /usr/local/Cellar/php/7.3.1... 0 symlinks removed
Linking /usr/local/Cellar/[email protected]/7.2.14... 25 symlinks created

If you need to have this software first in your PATH instead consider running:
  echo 'set -g fish_user_paths "/usr/local/opt/[email protected]/bin" $fish_user_paths' >> ~/.config/fish/config.fish
  echo 'set -g fish_user_paths "/usr/local/opt/[email protected]/sbin" $fish_user_paths' >> ~/.config/fish/config.fish
All done!

stephen at MacBook-Pro in ~/Desktop/tmp
$ ls                                                                                                                                                                                                                                 
101300

Changing line 25 from

if [ ${osx_version} > 101300 ]; then

to either if (( ${osx_version} > 101300 )); then or if [[ $(echo "$osx_version") -ge 101300 ]]; then fixes it

Can we have the default be to restart Valet if it is installed?

Trying this project out today to see if it will work for me switching between PHP versions. However, I use Valet and find that I need to specify -c=valet to make sure Valet is restarted.

Is there a reason for this? If not, if I provided a way to either make restarting Valet happen by default or by some other means (env config values, etc) would that be accepted?

Autoswitch $PATH for CLI

Hello,

Im wondering if a method of auto swithcing the $PATH variable for the PHP CLI can be created for this package? I imagine with the patterns in the .bash_profile declartions this is something that is doable.

#export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH"
export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"

Thanks for the package, really nice work!

Switches when variable not passed in

When attempting to switch if you leave off the version you want.

brew-php-switcher

Should not attempt to switch and exit out before switching occurs.

Skip apache mod_php always

There should be a config file where I can configured always to skip the apache mod_php conf (-s). So I dont need to add the -s.

Warning

phpswitch raises a warning when a PHP version is not installed.

Switching to php
Switching your shell
Error: No such keg: /usr/local/Cellar/php53

script leaves other php kegs left unlinked

Hello, thanks for sharing!

I noticed that after running this script, my other php kegs are left unlinked.

How to recreate

Verified no link issues:

$ brew doctor
Your system is ready to brew.

On php version 5.6:

$ php -v
PHP 5.6.16 (cli) (built: Nov 27 2015 10:28:34)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

Now switch to 5.5:

$ brew-php-switcher 55
Switching to php55
Switching your shell
Unlinking /usr/local/Cellar/php54/5.4.45_3... 4 symlinks removed
Unlinking /usr/local/Cellar/php55/5.5.30... 4 symlinks removed
Unlinking /usr/local/Cellar/php56/5.6.16... 358 symlinks removed
Unlinking /usr/local/Cellar/php70/7.0.0... 22 symlinks removed
Linking /usr/local/Cellar/php55/5.5.30... 17 symlinks created
You will need sudo power from now on
Switching your apache conf
Password:
Restarting apache
All done!

Double check php versions:

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
    php54
    php56
    php70

My other remaining kegs of php are now left unlinked.

Proposed Solution

Can we make it so that this script does not leave those kegs unlinked? Usually I switch versions with this:

$ brew unlink php55 && brew link --overwrite php55

Thoughts?

Add support for v7.3

Hello repository maintainer!

PHP 7.3 is going to release soon and Release Candidate versions are now available on php.net,
How can we switch to this version?

Thanks indeed

Tag a new version 2.5 for PHP 8.2 support

When I run brew update && brew upgrade brew-php-switcher
I'm getting the following output:

Already up-to-date.
Warning: brew-php-switcher 2.4 already installed

I would like to switch to PHP 8.2 to test some things. I'm seeing the update has already happened, but it looks like we just need to tag a new version for brew

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.