Php version reads as one version, when I need another - php

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

Related

Using PHP on macOS Monterey - many homebrew errors on reinstall after updating OS

I made the seemingly bad decision to update to macOS Monterey 12.3.1, and am having a hell of a time trying to get PHP working on it again. From what I've seen, Apple has decided that PHP is deprecated - at least from their machines, and they removed every php version and setting that I had set up for all my Laravel and Wordpress projects!
I tried reinstalling PHP using homebrew but I got a lot of errors about certain packages not being able to be downloaded due to authorization denial?
So then I attempted to uninstall and reinstall Homebrew, and I did the following:
Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Add the following to zshrc
eval "$(/opt/homebrew/bin/brew shellenv)"
Test brew version to see if it's working
brew --version
Run brew doctor to make sure everything is configured correctly
brew doctor
I also saw that it was likely that there would be libraries missing and that i should reinstall open ssl so i did that as well:
brew install openssl
Then for PHP I ran:
brew tap shivammathur/php
and then
brew install shivammathur/php/php#7.4
brew install shivammathur/php/php#8.0
and I even restarted the php services just in case
brew services restart shivammathur/php/php#7.4
brew services restart shivammathur/php/php#8.0
Then I ran
php -v
and I got the following error:
zsh: command not found: php
and which php says php not found
what the heck!
I then tried to unlink php and force a link to 7.4:
brew unlink php && brew link --overwrite --force php#7.4
and I got the following brew error:
Error: No such keg: /usr/local/Cellar/php
I tried digging into fixing this keg issue but i haven't been able to figure it out, do you have any suggestions on next steps
Check that Homebrew's bin directory i.e. $(brew --prefix)/bin is in your PATH.
If you want to link PHP 7.4, run
brew link --overwrite --force php#7.4
If you get an error mentioning that it is already linked, you can relink it by unlinking it first and linking it again to be sure. Make sure you unlink the correct version.
brew unlink php#7.4
brew link --overwrite --force php#7.4

PHP CLI on Apple M1 using Homebrew

I've followed this guide to install Homebrew on an M1 based Mac.
After that I ran
brew install php#7.4
which installed PHP successfully.
If I now run
brew upgrade php
I get
Error: php not installed
What I like to achieve is to update the PHP that comes shipped with macOS, which is 7.3.22 when I run php -v.
How can I update PHP using Homebrew? I understood that I need to put something in my PATH to point to the newer PHP version? Given this is a new machine I actually don't have a .bash_profile file, only a .zshrc (I'm using ZSH, I assume that this file will be used and that I don't need a .bash_profile?)
It's not advisable to upgrade the system-provided PHP, but it's also not necessary.
brew link can be used to decide which PHP is utilized. brew link php#7.4 should do the trick; this can be also used to switch PHP versions around, i.e. brew link php#8.0 will switch you over to that while leaving both versions installed and available directly.

homebrew - upgrade php broke php 5.6 dependency

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.

php dyld: Library not loaded for libldap

I installed ruby on my Mac OSX High Sierra and am running into issues now with my php installation for some reason. I'm on php 7.1.
Following this (also here) Github suggestion, I tried
brew update && brew reinstall php71
While installing, it broke at
==> Pouring php#7.1-7.1.23.high_sierra.bottle.tar.gz
==> /usr/local/Cellar/php#7.1/7.1.23/bin/pear config-set php_ini /usr/local/etc/php/7.1/php.ini system
With error:
dyld: Library not loaded: /usr/local/opt/openldap/lib/libldap-2.4.2.dylib
Referenced from: /usr/local/Cellar/php#7.1/7.1.23/bin/php
Reason: image not found
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall php#7.1`
Typing in php into terminal throws the same error.
Other things I've tried:
I thought perhaps it wasn't linked, so I also tried: brew unlink libldap && brew link libldap - but libldap is not supported by Homebrew
Then here, while unrelated to postgres, it does discuss the issue of libldap and says to install via brew install openldap (I guess libldap is referred to as openldap to Homebrew) - this installed fine but didn't resolve the issue
How can I fix this?
According to this issue, you need to install openldap and libiconv.
brew install openldap libiconv
I tried it and it worked for my system. I was originally missing the PHP intl extension.
It's worked for me:
brew reinstall openldap
Although I'm not sure why installing Ruby caused the issue, I solved the issue ultimately with:
According to this discussion, libldap is referred to as openldap to Homebrew. brew install openldap then ran php reinstall php71. This linked the libraries properly
The next issue was with libiconv, fortunately this is easily installed with brew install libiconv. Rerunning php install php71 solved the problem
I specifically had to uninstall the offending version. You can grab this broken version from the line that looked like this:
Referenced from: /usr/local/Cellar/php#7.1/7.1.23/bin/php
In OP's case, it was php#7.1. In my case it was php#7.3. After I ran the following based on my situation, everything worked
brew uninstall php#7.3
For those who can not resolve by brew install openldap libiconv,
try below command:
brew reinstall openldap
brew reinstall php#7.4
brew services restart php#7.4
This issue is discussed and tracked at https://github.com/Homebrew/homebrew-core/issues/32916
if you have two PHP running via brew as well a XAMPP, there could be issue in environment path in .bash_profile.
which php
Try above command to see current php path. If it not accurate, set appropriate path and comment other.
export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH
#export PATH=”/usr/local/opt/php#5.6/bin:/usr/local/opt/php#5.6/sbin:$PATH
After trying all above solutions. Finally uninstalling and reinstalling worked for me.
brew uninstall php
brew install php
For me, after running the following commands:
brew reinstall openldap
brew reinstall php#7.4
brew services restart php#7.4
I had to restart my computer for the error to stop and everything worked fine.

How do I reinstall php on a mac?

I have been wanting to upgrade php5 to php7 on my macbook but i just don't know how. I tried using homebrew and a couple other methods I found online but I just don't know how to complete it.
As a result php5 has been deleted from /usr/local.
How can i get php5 back and then how do i upgrade it to php7?
I want the newest version because I have a minecraft server that I run on my computer that used to use php5 but now requires php7. I have the latest macbook with the latest os.
As you are using homebrew, you can go with homebrew-php. You can install multiple version of PHP with this, and easily switch the version if you want
Or, you can use homebrew with php as usual
brew tap josegonzalez/php
brew tap homebrew/dupes
brew install php55
If you want to upgrade to PHP 7 but still keep current PHP 5, you should unlink PHP 5 first
brew unlink php55
brew install php70
Then you can use PHP 7.
And if you want to switch back to PHP 5, just unlink PHP 7 and link PHP 5
brew unlink php70
brew link php55

Categories