When installing brew install php#8.1 it automatically installs latest version 8.1.15. Due to the development purposes I need to install another minor version (e.g. 8.1.7). Since minor versions are hardcoded in formulas, it's not possible to install specific minor version out of the box. What is the easiest way to use an old formula if I could find it in the repo's commit history? I tried this as was advised in different SO thread:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/83b80f3b76c9cbd79e914f927a45a083b1d047e1/Formula/php.rb
But it literally won't let me to:
Error: Installation of php from a GitHub commit URL is unsupported! `brew extract php` to a stable tap on GitHub instead.
Any ideas?
Related
First of all, I'm sorry if I'm posting a duplicated question. I know there are a few threads about installing imagick on an local machine. But I really can't find any way to fix my php installation.
I want to install the imagick extension for PHP 8.0 But when I try to install with the pecl install imagick command I get the following error:
No releases available for package "pecl.php.net/imagick"
install failed
I am developing on a Macbook. Have a freshly installed Laravel Valet installation. Installed my PHP 8.0 (with homebrew, via valet) and tried to execute pecl install imagick.
I have re-installed imagick & pkg-config with brew reinstall imagick & brew reinstall pkg-config. In that order. After that, I still get the same report.
I have ran brew doctor but don't think there is anything useful in there that could help me. Only some broken symlinks and Unbrewed header files. If you want I can upload the full output, but someone needs to help/tell me how to upload such a big snippet. Just putting it in this question without formatting seems like a bit too much.
Possible duplicated that didn't help me so far:
pecl can't find imagick package
For me it solved with sudo pecl install imagick but that might not be the preferred route.
I have multiple versions of PHP installed on my localhost using homebrew:
the standard core php package (v7.3.12)
php 5.6 from exolnet/homebrew-deprecated
Now when I upgraded php to 7.3.12 recently it upgraded a dependency that php#5.6 requires and now I am getting this error:
dyld: Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
Referenced from: /usr/local/Cellar/php#5.6/5.6.40/bin/./php
Reason: image not found
[1] 83775 abort ./php
And when I navigate to /usr/local/opt/openssl/lib/ I see that I now have the upgraded libcrypto.1.1.dylib installed.
I've tried brew upgrade and reinstalling php#5.6 but no joy.
Does anyone have a suggestion? I really need both versions of php working on my localhost to continue development.
From my experience, trying to manage multiple PHP versions via homebrew is an absolute PITA, and I don't think I've ever got to the point where I can easily have both versions available side by side (until now!). Extensions are also supported, the details of which are provided later on in this answer.
That said, I have found a guide that gives some instructions on how to get this working and it works an absolute treat:
The linked guide references this method in the context of running PHP within Apache, so if that's your use case that's a nice little bonus for you too.
Now, because just posting links as answers on StackOverflow just isn't the done thing, I've detailed the main steps you need to follow in order below. Homebrew uses different paths on Apple Silicon hardware vs Intel because of course it does, so if I've missed any path changes please let me know so I can update my answer.
For anyone following this guide that doesn't yet have the prerequisites installed, ensure you have the Xcode command line tools and Homebrew installed and up to date.
If you want to check Homebrew for any issues, you can run
brew doctor
It's also never a bad idea to ensure that you have OpenSSL installed, especially if starting a fresh on macOS Monterey:
brew install openssl
So, let's get started.
Reset your environment
First, update everything then upgrade:
brew update
brew upgrade
brew cleanup
The reason for this is: "This will actually 'migrate' the core PHP packages (which are the only ones supported), but there's a bunch of symlinks utilized that could cause problems down the road, so after upgrading, we'll remove all PHP packages, to provide a fresh start"
Once you've done that, check what's actually installed:
brew list | grep php
Then remove whatever you find, for example:
brew uninstall --force php56 php56-apcu php56-opcache php56-xdebug
brew uninstall --force php70 php70-apcu php70-opcache php70-xdebug
brew uninstall --force php71 php71-apcu php71-opcache php71-xdebug
brew uninstall --force php72 php72-apcu php72-opcache php72-xdebug
brew cleanup
Double check there's nothing left:
brew list | grep php
and clean up any old configuration files:
Intel:
rm -Rf /usr/local/etc/php/*
Apple Silicon:
rm -Rf /opt/homebrew/etc/php/*
If have the exolnet/deprecated tap installed, you'll need to remove it first using
brew untap exolnet/deprecated
If you don't, you can get some weird conflicts
Add the new Tap and Install
We're then going to tap a different repository. This repository has many versions of PHP pre-built which may or may not work for you, however installation should be much faster as we don't have to compile from source.
brew tap shivammathur/php
You can then install any PHP versions you require:
brew install shivammathur/php/php#7.0
brew install shivammathur/php/php#7.1
brew install shivammathur/php/php#7.2
brew install shivammathur/php/php#7.3
brew install shivammathur/php/php#7.4
brew install shivammathur/php/php#8.0
At the time of writing, this repository has versions 5.6 through 8.1 available for installation
The php.ini files are located in the following directories:
Intel:
/usr/local/etc/php/7.0/php.ini
/usr/local/etc/php/7.1/php.ini
/usr/local/etc/php/7.2/php.ini
/usr/local/etc/php/7.3/php.ini
/usr/local/etc/php/7.4/php.ini
/usr/local/etc/php/8.0/php.ini
Apple Silicon:
/opt/homebrew/etc/php/7.0/php.ini
/opt/homebrew/etc/php/7.1/php.ini
/opt/homebrew/etc/php/7.2/php.ini
/opt/homebrew/etc/php/7.3/php.ini
/opt/homebrew/etc/php/7.4/php.ini
/opt/homebrew/etc/php/8.0/php.ini
Link your desired version
Once you've got here, close and reopen any terminal windows you have open to avoid strange path issues.
Now, these versions are installed, but not linked. To switch to PHP 7.3 for example, run the following command:
brew unlink php && brew link --overwrite --force php#7.3
And then check we have the correct version:
php -v
If we want to switch to PHP 7.4:
brew unlink php && brew link --overwrite --force php#7.4
And then check we have the correct version:
php -v
Easier Switching
If you want a faster way of switching PHP versions, check out the sPHP script from rhukster
You can install this by running:
Intel:
curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw/adc8c149876bff14a33e3ac351588fdbe8172c07/sphp.sh > /usr/local/bin/sphp
chmod +x /usr/local/bin/sphp
Apple Silicon:
curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw/adc8c149876bff14a33e3ac351588fdbe8172c07/sphp.sh > /opt/homebrew/bin/sphp
chmod +x /opt/homebrew/bin/sphp
and execute it using:
sphp 8.0
Of course, with anything like this YMMV, but this should hopefully be a good starting point and actually get you where you need to be and remove some headaches.
What about extensions?
Well I'm glad you asked. For the later versions, pecl does work. However, if you want to install xdebug for 5.6 for example, pecl throws its toys out of its pram.
There is another repository you can tap, specifically for extensions:
brew tap shivammathur/extensions
Once you've done this, it's as simple as running:
brew install xdebug#5.6
brew install xdebug#8.1
The list of available extensions is detailed in the link above. I won't include them here because it's a dynamic list and it'll soon be out of date, but most of them support 5.6 through to 8.1
Wrap up
Having followed this process myself, this is the easiest approach I'm yet to find for managing multiple PHP versions on macOS. Feel free to run brew doctor and brew cleanup at any points during the process, it can't hurt after all and might in fact help with debugging any issues you happen across. That said, my environment was an absolute mess and this tidied it up in about ten minutes. The longest step in this process for me was updating Homebrew itself.
On mac/terminal, I'm attempting to set up a local server with laravel but keep getting error that the php version is not up to date. I have attempted to install the needed 5.6 version via this tutorial, but I'm assuming it needs to be updated in my bash, possibly all things that are using it like Composer. I am not certain how to update the bash correctly or really what to do from here. https://coolestguidesontheplanet.com/upgrade-php-on-osx/ is how I updated. Also, if you have any suggestions as to what I can be learning to prevent this question in the future that would be much appreciated/where to start. EDIT: error: This package requires php >=5.6.4 but your PHP version (5.5.36) does not satisfy that requirement. terminal command: composer update
Install php from homebrew
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew unlink php56
brew install php70see if it works for you. I had to alias to php7 in my ~/.bash_profile
I need to install PHP 5.3 on Debian. If I were to perform a regular install of PHP I would get version 5.4.
I understand that I can run apt-get install <package-name>=<package-version-number> to install a specific version. But I don't know what the exact package version number is for PHP 5.3.
I've ran apt-cache showpkg php5 and apt-cache madison php5 but they only list the current version.
How can I identify the correct version number to use to install PHP 5.3?
I have no idea if it's available in some apt command, but you can get the full list here: http://snapshot.debian.org/package/php5/
It seems the latest PHP 5.3 for Debian is 5.3.10-2: http://snapshot.debian.org/package/php5/5.3.10-2/
To install a package from snapshot, you have to add an entry to your /etc/apt/sources.list matching the packages you want, this entry can be found in the "pool" link. For instance, for php5 5.3.10-2 the pool link is http://snapshot.debian.org/archive/debian/20120221T041601Z/pool/main/p/php5/ so you need to add http://snapshot.debian.org/archive/debian/20120221T041601Z/ to you sources.list:
deb http://snapshot.debian.org/archive/debian/20120221T041601Z/ unstable main
deb-src http://snapshot.debian.org/archive/debian/20120221T041601Z/ unstable main
Those entries needs to be set to unstable, that's because snapshots give you the first time the packages apparead in the debian packages, and most often that's in unstable (but I guess it could be on experimental as well).
Next you need to update while telling apt to ignore packages expiration date:
apt-get -o Acquire::Check-Valid-Until=false update
If you're using aptitude, that's:
aptitude -o Acquire::Check-Valid-Until=false update
Now you can install your specific version of php5:
apt-get install php5=5.3.10-2
Now, as you added an unstable repository to your installation, you may want to set priority to stable packages, see: http://www.imped.net/2007/07/20/apt-pinning-installing-unstable-packages-on-stable-debian/
phpinfo() function shows that my PHP version (5.1.6) is installed --without-pear in the configure command section.
How do I install pear?
The Getting and installing the PEAR package manager page should help you : it gives informations on how to install the PEAR package manager, on both windows, Linux, and Mac.
Basically, if your Linux distribution comes with a PEAP package, you should install it.
For instance, on Ubuntu1, there is a php-pear package ; so, you'd use :
apt-get install php-pear
Else, if it doesn't, with a version of PHP >= 5.3, you should be able to use this :
$ wget http://pear.php.net/go-pear.phar
$ php go-pear.phar
With PHP 5.1, though, this is not going to work, as phar support has been added in PHP 5.3...
As a sidenote : PHP 5.1 is really outdated !
PHP 5.3 is more than one year and a half old ; even PHP 5.2 is not maintained anymore... maybe you should consider upgrading ?
1It seems you are running some kind of Redhat-based distribution, but I don't have one of those, so I cannot say if there is a PEAR package for it -- there is probably one, though.
--without-pear only means that the PEAR bits were not immediately created when PHP was compiled.
This usually happens when an operating system vendor that provides packages and wants to split off bits and pieces into their own individually installable parts.
Given the age of the PHP you're talking about, you're probably on RHEL or a derivative like CentOS. Check the package manager for a php-pear package.