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

Last update: May 23, 2022

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

GitHub

https://github.com/philcook/brew-php-switcher
Comments
  • 1. 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 🙂

    Reviewed by chrisdeeming at 2018-12-07 22:05
  • 2. 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?

    Reviewed by MartinPeverelli at 2018-04-04 17:38
  • 3. 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?

    Reviewed by black-snow at 2018-03-09 16:22
  • 4. 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
    
    Reviewed by phoenixg at 2018-05-02 07:08
  • 5. 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```
    Reviewed by ravisharmaa at 2018-12-10 18:10
  • 6. 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

    Reviewed by ikari7789 at 2018-04-01 10:36
  • 7. 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?

    Reviewed by bkdotcom at 2019-10-11 13:22
  • 8. 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.

    Reviewed by mirfilip at 2015-07-15 21:33
  • 9. 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?

    Reviewed by ikari7789 at 2018-10-11 10:49
  • 10. 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

    Reviewed by abolfazl-moeini at 2018-10-03 12:31
  • 11. 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
    
    Reviewed by phoenixg at 2018-07-09 10:37
  • 12. 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.

    Reviewed by eydun at 2022-05-12 15:49
  • 13. 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.

    Reviewed by weiyunpeng at 2019-11-16 03:25
  • 14. 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.

    Reviewed by i-am-socket at 2018-02-07 18:36
  • 15. 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?

    Reviewed by simensen at 2017-12-11 17:39
  • 16. 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

    Reviewed by jonom at 2017-07-12 19:45
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

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!

Dec 23, 2021
Monitor for any changes in your php application and automatically restart it (suitable for async apps).
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.

May 13, 2022
A development tool for all your projects that is fast, easy, powerful and liberating
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

May 25, 2022
🎲Neard is a portable WAMP software stack involving useful binaries, tools and applications for your web development.
🎲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

May 11, 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

Oct 22, 2021
Docker Containers for simple Laravel development.
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

May 19, 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

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

Apr 26, 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

May 20, 2022
Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
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

May 24, 2022
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

May 16, 2022
A modern Docker LAMP stack and MEAN stack for local development
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

May 26, 2022
Up and running with small Docker environments
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

May 20, 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

Mar 27, 2022
Vagrant-boxes - Setup scripts and docs for my vagrant boxes, primarily aimed at Web/SilverStripe developement

zauberfisch's vagrant boxes zauberfisch/silverstripe-debian64 Debian 10 x86_64 LAMP Box with many extra features, pre-configured for SilverStripe Sour

Jan 24, 2020
This is a dockerized environment for testing and developing things on the fatfree-core.
This is a dockerized environment for testing and developing things on the fatfree-core.

F3 development bench This is a dockerized environment for testing and developing things on the fatfree-core. It uses Docker to spin up multiple contai

Mar 29, 2022
Phansible - generate Vagrant + Ansible dev environments for PHP

Phansible Phansible is a simple generator for Vagrant projects, targeting PHP development environments, using Ansible as Provisioner. It was inspired

May 14, 2022