144

I try to install php@7.3 using brew. But, it return error because it is versioned formula. What is it?

command: brew install php@7.3

result: Error: php@7.3 has been disabled because it is a versioned formula!

Elbo Shindi Pangestu
  • 2,021
  • 2
  • 12
  • 24

7 Answers7

275

You can only install supported versions of PHP with brew. However, there is the tap shivammathur/php which can be used to install unsupported version of PHP.

  1. brew tap shivammathur/php
  2. brew install shivammathur/php/php@7.3
  3. brew link php@7.3

The first step only needs to be done once. After adding the tap, you can install PHP version 5.6 - 8.2.

Jason FB
  • 4,752
  • 3
  • 38
  • 69
derhansen
  • 5,585
  • 1
  • 19
  • 29
  • 9
    This is correct but i needed to do a few more steps. Found in https://github.com/shivammathur/homebrew-php and THIS->https://github.com/shivammathur/homebrew-php/wiki/Cleanup – Steve Jan 24 '22 at 20:15
  • 1
    I used brew to install python and it deprecated my php! wth! SO this sorted it. Thanks! – dustbuster Mar 15 '23 at 19:53
  • Thank you guys, this has saved tons of effort. – Imran Zahoor May 06 '23 at 18:27
70

I applied the same instructions given by @derhansen and worked very well for php@7.4:

brew tap shivammathur/php
brew install shivammathur/php/php@7.4
brew link php@7.4
Carlos J. Ramirez
  • 1,049
  • 7
  • 9
  • 8
    this is just duplicating info 98% of the content in the accepted answer. this should just be a comment to the original. – oligofren Jan 05 '23 at 06:50
  • 7
    And yet, I was happy to copy and paste this for php 7.4 /grin. I'm now smiling at the idea of making an answer now for php@8.0, knowing that it will become useful to someone on Nov 27, 2023 (not really do it, but smiling at the thought) – Daryn Jan 05 '23 at 14:57
  • Well, this worked for me. – Neri Jul 08 '23 at 14:11
62

You can also edit the formula and re-enable it. These steps worked for me in May 2023:

  1. brew edit php@7.4
  2. Look for disable! date: "2022-11-28", because: :versioned_formula. Change 2022 to 2024 (or later).
  3. HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source php@7.4

Notes:

  • A recent Homebrew change now requires the use of HOMEBREW_NO_INSTALL_FROM_API=1
  • Although the bottles still exist online, the binaries are broken due to being linked with an older version of icu4c (v71) than what Homebrew installs. So you must use --build-from-source and compile PHP yourself.
Mike Richardson
  • 721
  • 3
  • 3
22

For anyone having this issue 2023 (and beyond)

The accepted answer is an unnessercery step.

@Mike's answer is the better one, but is missing one important step.

HOMEBREW_NO_INSTALL_FROM_API=1 brew install php@7.3

HOMEBREW_NO_INSTALL_FROM_API=1 brew install php@7.4

HOMEBREW_NO_INSTALL_FROM_API=1 brew install php@8.0

HOMEBREW_NO_INSTALL_FROM_API=1 brew install php@8.1

Brew tells you, when you edit the Formula:

Warning: Unless `HOMEBREW_NO_INSTALL_FROM_API` is set when running
`brew install`, it will ignore your locally edited formula.
Editing /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/php@7.4.rb
Warning: Using code because no editor was set in the environment.
This may change in the future, so we recommend setting EDITOR,
or HOMEBREW_EDITOR to your preferred text editor.

This way, you still use the official formula. This of course, works for any formula.

So, just remove the following two lines from the formula:

  brew edit {{ formula }} // ex: brew edit php@7.4

  keg_only :versioned_formula

  disable! date: "2022-11-28", because: :versioned_formula
Anuga
  • 2,619
  • 1
  • 18
  • 27
8

When you are using homebrew to install PHP you need to know the versions that are been supported by homebrew. If you need to install an unsupported version you can do it by running these commands

brew tap shivammathur/php
brew install shivammathur/php/php@7.4
brew link php@7.4

And then if ypu need to check the current version and then shift between php version you can run

php -v
brew unlink php
brew link php@7.4

rasif sahl
  • 172
  • 1
  • 8
1

BTW, brew install php@7.4 gives out same warning, but does install php7, so this could be an option

ReDetection
  • 3,146
  • 2
  • 23
  • 40
  • 1
    I get the same error on php@7.4 now, because it too is now unsupported: https://www.php.net/supported-versions.php. There's this line in the php@7.4.rb brew file: `disable! date: "2022-11-28", because: :versioned_formula` – Peter W Jan 02 '23 at 11:51
  • 5
    I wonder why did they put a timebomb instead of a warning. Unsupported software is not the end of the world – ReDetection Feb 27 '23 at 14:48
0

I was facing the same problem with Homebrew. The following steps resolved it, combining ideas from phpbrew#1249:

  1. Edit the formulae
    brew edit php@7.4
    
  2. Comment out or remove the date-based validation line, so that you can use the formula at all:
    disable! date: "2022-11-28", because: :versioned_formula
    
  3. Add the following lines after the block relating to "pkg-config" to make pkg-config find the compile headers of openssl v1.1.1 before the ones of v3 (which do not define RSA_SSLV23_PADDING):
    ENV["PKG_CONFIG_PATH"] = "#{Formula["openssl@1.1"].opt_prefix}/lib/pkgconfig:#{ENV["PKG_CONFIG_PATH"]}"
    system "echo", ENV["PKG_CONFIG_PATH"]
    
  4. Add OpenSSL flags directly afterwards:
    ENV["OPENSSL_CFLAGS"] = "-I#{Formula["openssl@1.1"].opt_include}"
    ENV["OPENSSL_LIBS"] = "-L#{Formula["openssl@1.1"].opt_prefix}/lib -lcrypto -lssl"
    
  5. In the args array for configure, replace --with-openssl with the following:
    --with-openssl=shared,#{Formula["openssl@1.1"].opt_prefix}
    
  6. Save and exit
  7. Reinstall PHP 7.4 from source using the locally edited formulae:
    HOMEBREW_NO_INSTALL_FROM_API=1 brew reinstall -s php@7.4
    
sun
  • 991
  • 9
  • 13