Skip to main content

In terminal I ran a regular command - compose update.  Something I've completed thousands of times previously.  However, this time I received the following response:

env: php: No such file or directory

 

What gives?

Well, thinking through what had recently changed... The only major change was upgrading OSX to Monterey.  So a little of Googling and found yep this could be the cause.  PHP has been removed from MacOS since v12 (Monterey), so you first need to install it on your own to use it.  For a OSX user, the easiest way to do this is using Homebrew.

brew install php@7.4 brew-php-switcher

Note, obviously I'm installing PHP 7.4, however you can change this to 8.0 or 8.1 depending on your requirements.

Once PHP has been installed, you will need to restart through

brew services restart php@7.4

To which you will see the following output

==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 1708, done.
remote: Counting objects: 100% (587/587), done.
remote: Compressing objects: 100% (345/345), done.
remote: Total 1708 (delta 259), reused 542 (delta 228), pack-reused 1121
Receiving objects: 100% (1708/1708), 492.28 KiB | 4.83 MiB/s, done.
Resolving deltas: 100% (735/735), done.
Tapped 1 command (44 files, 629.8KB).
==> Successfully started `php@7.4` (label: homebrew.mxcl.php@7.4)

 

PHP is installed, but is it running?

Checking if php is running

How to check if PHP is running?  Execute the command:

which php

However, the response was

php not found

Hmmm, seems I need to link PHP so it can be found.  Which is achieved by:

brew link php@7.4

And you'll see the the following in Terminal

Linking /usr/local/Cellar/php@7.4/7.4.27... 25 symlinks created.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc

Now if you run which php, the output is looking much better

which php
/usr/local/bin/php

 

Back to my original command

composer update

The response...

Loading composer repositories with package information
Updating dependencies

And on it goes.  Back in action!

Related articles

Andrew Fletcher05 Sep 2022
Terminal commands - find
Find by file name To perform a find command in terminal use find / -name php.ini -type f find / -name {filename} {type parameters} Note there are many parameters in the commands, so I'll cover a couple regular expressions here.  Such as,  -name matches the...
Andrew Fletcher11 Aug 2022
Using bash script to overwrite files and directories
I had generated a backup of key directories on the server - see Create a Ubuntu backup shell script.  With a backup in hand, now it was time to test how to unpack a backup and overwrite the directories. First I unpacked the backup to a temporary directory tmp-cc. Now I wanted to...
Andrew Fletcher11 Aug 2022
Create a Ubuntu backup shell script
An approach to generating a backup server is using a shell script.  A script can define directories to backup, and pass those directories as arguments to the tar utility, which creates an archive file. The archive file can then be moved or copied to another location.   Example Shell...