Brew PHP switcher is a simple shell script to switch your apache and CLI quickly between major versions of PHP

Overview

Brew PHP Switcher Build Status

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 or 8.0 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

Comments
  • Update switcher to support PHP 7.3

    Update switcher to support PHP 7.3

    PHP 7.3 was released yesterday and the relevant brew formulas were made available today so a quick merging of these changes to support [email protected] would be greatly appreciated @philcook 🙂

    opened by chrisdeeming 10
  • No available formula with the name

    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?

    opened by MartinPeverelli 9
  • new libphp7.so path

    new libphp7.so path

    It seems like the libphp7.so will now be found at /usr/local/opt/php72/lib/httpd/modules/libphp7.so (see Homebrew/homebrew-core#25018).

    Is brew-php-switcher ready for this?

    opened by black-snow 9
  • Not working anymore after homebrew switched the core

    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
    
    opened by phoenixg 8
  • Cannot switch to PHP @7.1

    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```
    opened by ravisharmaa 5
  • Update for new PHP packages from Homebrew

    Update for new PHP packages from Homebrew

    Homebrew decided to change the way that they manage PHP. It has some big differences, especially in the package names.

    See https://github.com/Homebrew/homebrew-php/issues/4721

    opened by ikari7789 5
  • icu4c PHP dependency

    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?

    wontfix 
    opened by bkdotcom 4
  • Add initial support for php70 #7

    Add initial support for php70 #7

    Hi, just a quick take on mentioned task. Please review it, it has been ages since I have done any scripting in bash.

    Two things to mention:

    • I thought about naming convention for php7x. Even though it's still beta, I went on with current conversion and didn't do anything like 70b or similar.
    • As for php7x apache module name and key for httpd.conf got changed, I needed some conditional logic.

    Also, I noticed there is something broken with substitution of LoadModule php5_module ... in httpd.conf in HEAD. It's not related to my changes. I didn't change any logic except naming, but I will revisit the matter later.

    opened by mirfilip 4
  • Fork for maintainability?

    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?

    opened by ikari7789 3
  • Add support for v7.3

    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

    opened by abolfazl-moeini 3
  • Error: No available formula with the name

    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
    
    opened by phoenixg 3
  • apache config does not change

    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.

    opened by eydun 2
  • bison: undefined method `uses_from_macos'

    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.

    opened by weiyunpeng 0
  • Error restarting Brew Apache after Switching PHP Versions

    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.

    opened by i-am-socket 0
  • Can we have the default be to restart Valet if it is installed?

    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?

    opened by simensen 1
Releases(v2.4)
Owner
Phil Cook
Phil Cook
Docker Shortie, simplifying calls to CLI commands inside docker containers.

What is DockTie Is a simple wrapper script for commands inside docker container(s). So for instance, what you would normally run as: docker-compo

null 3 Mar 31, 2022
A package that allows you to generate simple and fast Docker configurations for your Laravel application!

A package that allows you to generate simple and fast Docker configurations for your Laravel application!

Lucas Nepomuceno 3 Oct 8, 2022
Finally a sane way to register available commands and arguments and match your command line in PHP

clue/commander Finally a sane way to register available commands and arguments and match your command line in PHP. You want to build a command line in

Christian LĂĽck 172 Nov 27, 2022
Monitor for any changes in your php application and automatically restart it (suitable for async apps).

PHP-watcher PHP-watcher helps develop long-running PHP applications by automatically restarting them when file changes in the directory are detected.

Sergey Zhuk 373 Dec 21, 2022
A development tool for all your projects that is fast, easy, powerful and liberating

Lando A Liberating Dev Tool For All Your Projects The local development and DevOps tool trusted by professional developers across the galaxy. Free you

Lando 3.6k Jan 7, 2023
🎲Neard is a portable WAMP software stack involving useful binaries, tools and applications for your web development.

About Neard is a portable WAMP software stack involving useful binaries, tools and applications for your web development. It also offers several versi

Neard 335 Dec 22, 2022
Demo of how you can run your Laravel app with Docker Compose. Look at docker-compose.yml and the docker folder. The rest is just a clean Laravel + Horizon install.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Matt 5 Oct 22, 2021
Docker Containers for simple Laravel development.

Docker containers of Laravel development. Docker Containers for simple Laravel development. Prerequisites This package only works for Linux users righ

Steve Azzopardi 14 May 19, 2022
Dockerized PHP development stack: Nginx, MySQL, MongoDB, PHP-FPM, HHVM, Memcached, Redis, Elasticsearch and RabbitMQ

PHP Dockerized Dockerized PHP development stack: Nginx, MySQL, MongoDB, PHP-FPM, HHVM, Memcached, Redis, Elasticsearch and RabbitMQ PHP Dockerized giv

Kasper Isager DalsgarĂ° 1.1k Dec 30, 2022
Laravel 5 with Dockerized Gulp, PHP-FPM, MySQL and nginx using docker-compose

docker-laravel Laravel 5 with Dockerized PHP-FPM, MySQL and nginx using docker-compose Usage Get Composer docker-compose run --rm phpnginx curl -O htt

Harsh Vakharia 83 Feb 8, 2022
Docker with PHP 7.4 fpm, Nginx, Composer, PhpUnit and MaridaDB

Clean Docker with PHP Docker with PHP 7.4 fpm, Nginx, Composer, PhpUnit and MariaDB Starting app docker-compose up -d Main page

Grzegorz Bielski 7 Nov 17, 2022
ServD - a Docker PHP development environment heavily inspired by Laravel Valet and Laradock

ServD ServD is a Docker PHP development environment heavily inspired by Laravel Valet and Laradock, it supports multiple projects within a working dir

Matt Clinton 2 May 13, 2022
Vagrant is a tool for building and distributing development environments.

Vagrant Website: https://www.vagrantup.com/ Source: https://github.com/hashicorp/vagrant HashiCorp Discuss: https://discuss.hashicorp.com/c/vagrant/24

HashiCorp 24.8k Jan 2, 2023
Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:

Latest Salt Documentation Open an issue (bug report, feature request, etc.) Salt is the world’s fastest, most intelligent and scalable automation engi

SaltStack 13k Jan 8, 2023
Server automation framework and application

Puppet Puppet, an automated administrative engine for your Linux, Unix, and Windows systems, performs administrative tasks (such as adding users, inst

Puppet 6.8k Dec 31, 2022
A modern Docker LAMP stack and MEAN stack for local development

The Devilbox Usage | Architecture | Community | Features | Intranet | Screenshots | Contributing | Logos | License Support for valid https out of the

cytopia 4k Jan 8, 2023
Up and running with small Docker environments

Vessel Up and running with small Docker dev environments. Documentation Full documentation can be found at https://vessel.shippingdocker.com. Install

Shipping Docker 1.1k Dec 17, 2022
Oxygen Builder's better workflow and environment

Oxygen Builder's better workflow and environment Built with ❤️ Official Website | Documentation | Change Log Supporting Artifact is an open source pro

AncientWorks 10 Dec 3, 2022