php: command not found Command PhaseScriptExecution failed with a nonzero exit code - php

I updated to Monterey and I am trying to build my xcode project.
I have a custom php script that runs in Build Phases and I am getting the following error.
/Users/jonathan/Library/Developer/Xcode/DerivedData/SwiftApp-aboxvgocemtxyjcdbgadfktiyxvd/Build/Intermediates.noindex/SwiftApp.build/Debug Dev-iphoneos/SiteSelectedLibraryApp.build/Script-025223DA20C597E100D80A6A.sh: line 3: php: command not found
Command PhaseScriptExecution failed with a nonzero exit code
I have installed php with brew install php#8.0. I can run php in the terminal now but xcode can't seem to find it.

I ran into the same issue.
After a lot of searching over the internet, I found this solution.
It would help if you went to this library: https://github.com/shivammathur/homebrew-php
Follow these steps:
On macOS, install Xcode Command Line Utilities:
xcode-select --install
Install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Fetch the formulae in this tap:
brew tap shivammathur/php
Install PHP 8.0
brew install shivammathur/php/php#8.0
After installing you have to link it:
brew link --overwrite --force shivammathur/php/php#8.0
If this command throws an error, then select any one path it shows on the terminal and execute it:
For me, I selected this path to override:
echo 'export PATH="/usr/local/opt/php#8.0/bin:$PATH"' >> ~/.zshrc
Restart the terminal and test your PHP version:
php -v
Now check with this command, does it gives you the waring of already linked:
brew link --overwrite --force shivammathur/php/php#8.0
That's it.
Now Xcode will run the PHP script without any error.

Related

Error installing php 71 with homebrew on my mac

I have been developing with Vallet for some time now. Today i wanted to update laravel 5.4 to 5.5. Before doing so i run composer global update. Causing Vallet to stop working.
Fist i tried to do the following:
cd ~/.composer/
sudo chown -R $(whoami) vendor
source: https://laracasts.com/discuss/channels/general-discussion/getting-valet-not-found-error
I did not solve the issue. Then i decided to reinstall Vallet. Hereby i did the following:
I followed this: https://github.com/laravel/valet/issues/321
Stop and uninstall services
sudo brew services stop php71 dnsmasq nginx
brew uninstall php71 dnsmasq nginx
Remove related config files and valet home folder
sudo rm -r /usr/local/etc/php /usr/local/etc/nginx /usr/local/etc/dnsmasq.conf
sudo rm -r ~/.valet /var/root/.valet
Install services i tried this:
brew install php71
$ brew tap homebrew/php
$ brew install php71
brew install homebrew/php/php71
All gave the following error:
MacBook-Pro:~ mblivier$ brew install homebrew/php/php71
==> Installing php71 from homebrew/php Error: The following formula: php71
cannot be installed as a binary package and must be built from source.
Install the Command Line Tools:xcode-select --install
I new in this and don't know how to solve this. Any suggestions how to install php and go further with reinstalling Vallet?
homebrew is installed and working
You need xcode to build php, so first run:
xcode-select --install
to install xcode and later you can brew install php71
This is answer for your comment, I can't post as comment, need to post because is length limited.
There is one of two things going on here, either you didn't install PHP, or PHP is installed and not currently in any of system aware paths. First I would try to find PHP and make sure it exists:
$ find / -name php -type f
You should see something like:
/path/to/your/php/bin/php
If PHP binary does exist, check your path:
$ echo $PATH
If it does not exist, recompile php.
If PHP exists on your system, make sure the path to the /bin/php file is included. You can edit your ~/.bash_profile and add the custom path like this:
PATH=$PATH:/path/to/your/php/bin/
....
export PATH
Then save and reload the file to ensure your current session has access to new path changes:
$ source ~/.bash_profile
With any luck you can now do a php -v and see the version response.

php -v returns dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib

I was trying to install Valet and for a mistake I uninstall php from brew, now I reinstall php, if I go to a phpinfo() file on apache I can see
PHP Version 7.1.23
but if I do php -v on console, or something other php command i get:
dyld: Library not loaded:
/usr/local/opt/readline/lib/libreadline.7.dylib Referenced from:
/usr/local/bin/php Reason: image not found Abort trap: 6
Im on Mac Os Sierra
There's a couple of ways you could try to resolve this:
$ brew link readline
or perhaps:
$ brew link readline --force
If that doesn't work try:
$ cd /usr/local/opt/readline/lib/
$ ln -s libreadline.dylib libreadline.7.dylib
↳ Github Discussion : libreadline (image not found)
For me, I had php 5.4 installed, but an upgrade to php 7.3 worked for me.
brew install php#7.3
Then you'll likely need to add the new php version in your path. This basically means that when you load up your shell it knows where find the path to the files that you are using. For me, since I'm using zshrc that command is:
echo 'export PATH="/usr/local/opt/php#7.3/bin:$PATH"' >> ~/.zshrc
For you, if you have all your path and aliases in bash profile then the command would be this instead:
echo 'export PATH="/usr/local/opt/php#7.3/bin:$PATH"' >> ~/.bash_profile
Then, all you need to do is either source your zshrc or your bash_profile file, OR close that tab and open a new one. The source command basically says "hey, make sure you have an updated list of my aliases and path info". This naturally happens when you open a new shell, but you can force that with a command like:
source ~/.bash_profile
And then it worked for me. Good luck.
Try this:
$ cd /usr/local/opt/readline/lib/
$ ln -s libreadline.dylib libreadline.7.dylib
Then :
brew unlink readline && brew link --force readline

dyld library not loaded - PHP, Laravel, Composer command line commands not working

I updated my PHP version to 7.2 via homebrew and now any laravel,php, and composer command brings this error. I've googled the error though no luck! What do I need to install? Why has this now became an error?
libldap-2.4.2.dylib
dyld: Library not loaded: /usr/local/opt/openldap/lib/libldap-2.4.2.dylib
Referenced from: /usr/local/bin/php
Reason: image not found
Abort trap: 6
I fixed it -
I ran....
echo 'export PATH="/usr/local/opt/openldap/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/openldap/sbin:$PATH"' >> ~/.bash_profile
export LDFLAGS="-L/usr/local/opt/openldap/lib"
export CPPFLAGS="-I/usr/local/opt/openldap/include"
Then after words a similar error came up that libiconv was not loaded and did not match the PHP version I had, so I ran...
brew install libiconv
On a side note, I found that .bash_profile php path was reference to /usr/local/opt/ instead of XAMPP.
which php
Try above command to see current php path. If it not proper, set the right one, such as:
export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH
For me it was a little different, I installed php 8.1 (previously I had 7.4) with brew but it didn't link so I had to run the link command
brew link php#8.1
Then
echo 'export PATH="/opt/homebrew/opt/php#8.1/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/php#8.1/sbin:$PATH"' >> ~/.zshrc
and it's solved :D

brew link php71: Could not symlink sbin/php-fpm

I'm trying to install Laravel Valet, which requires php 7.1, but when i run brew install php71, I get the following error:
==> Pouring php71-7.1.10_21.high_sierra.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink sbin/php-fpm
/usr/local/sbin is not writable.
I get the same error when i run brew link php71. If i run php -v, I actually see that I'm currently running PHP 7.1.7.
But when I run valet install, I get:
[DomainException]
Unable to determine linked PHP.
I don't even have an sbin directory in /usr/local.
Any suggestions?
I solved this problem by first creating the directory sbin:
sudo mkdir /usr/local/sbin
then if you are like me using macOS highSierra 10+ you need to run:
sudo chown -R $(whoami) $(brew --prefix)/sbin
after this
brew link php
Installing Laravel Valet, I had a similar issue with sbin not being writable. I had to make the directory, then utilized the solution included at this page. This finally allowed me the proper permissions to run a brew link command with a previously installed version of php 7.1.

Linker error from homebrew installing php when running make

I'm attempting to install php and php-cgi with Homebrew.
brew install https://github.com/ampt/homebrew/raw/php/Library/Formula/php.rb
Using this method returns the following errors.
==> make
clang: clangerror: : linker command failed with exit code 1 (use -v to see invocation)error:
linker command failed with exit code 1 (use -v to see invocation)
make: *** [sapi/cli/php] Error 1
make: *** Waiting for unfinished jobs....
make: *** [sapi/cgi/php-cgi] Error 1
I've updated Homebrew, and the XCode command line tools. The only warning brew doctor gives me is that a few Python "config" scripts exist outside my system or Homebrew directories.
Anyone know what the issue could be? Where can I look for more detailed error messages?
I'm not familiar with the ampt tap, when I grabbed php I used the josegonzalez tap. You could try that.
$ brew tap josegonzalez/homebrew-php
You can also get more information by using the -vd options to brew install.
$ brew install -vd https://github.com/ampt/homebrew/raw/php/Library/Formula/php.rb
I just unlinked my 5.3.13 php from josegonzalez and ran the above command. With the -vd I can see the ./configure command run and all the output from it as well as the commands make invokes and compiler output. Whew, this is taking a while to build.
It does fail for me with this output
==> cp ./php.ini-production /usr/local/Cellar/php/5.3.10/etc/php.ini
cp ./php.ini-production /usr/local/Cellar/php/5.3.10/etc/php.ini
cp: /usr/local/Cellar/php/5.3.10/etc/php.ini: No such file or directory
/usr/local/Library/Homebrew/formula.rb:553:in `system
Looks like the Formula never creates ${prefix}/etc. I blame the formula. Try josegonzalez tap.
$ rm /Library/Caches/Homebrew/Formula/php.rb
$ brew tap jozegonzalez/homebrew-php
$ brew install php53
As a comment on homebrew-php repository just force link libxml2
brew link libxml2 --force

Categories