The two programs have different ideas about where to look. They can also be implemented in different ways on different systems. On mine, whereis is a binary executable and which is a Bourne shell script.
If you'd like yet other opinions on where something is, try these:
type -a php
and
locate php
From the whereisman page:
whereis has a hard-coded path, so may not always find what you’re looking for.
From the whichman page:
which returns the pathnames of the files which would be executed in the
current environment, had its arguments been given as commands in a
strictly POSIX-conformant shell. It does this by searching the PATH
for executable files matching the names of the arguments.
So whereis searches a hard-coded path, which uses the $PATH variable, locate uses a database of the (by default) whole file system, and type, which is a Bash builtin, looks in the $PATH, the builtins, aliases and function definitions.
I use type and locate primarily and only very rarely use the other two since they are relatively limited in capability.
Oh, and in order to answer your question, which, because it searches $PATH, is more likely to show you the location which will actually run if you type the command "php". And type is probably going to be even better in cases where you have aliases or functions of the same name since they are executed preferentially over the $PATH location. Note that all of this is system dependent and also dependent on the shell that you are using (my assumption is that it is Bash). On my system, using Bash, the order is functions, aliases, builtins, then $PATH (in the order in which directories are listed there). Compare the output of these various commands to:
The two programs have different ideas about where to look. They can also be implemented in different ways on different systems. On mine,
whereis
is a binary executable andwhich
is a Bourne shell script.If you'd like yet other opinions on where something is, try these:
and
From the
whereis
man
page:From the
which
man
page:So
whereis
searches a hard-coded path,which
uses the $PATH variable,locate
uses a database of the (by default) whole file system, andtype
, which is a Bash builtin, looks in the $PATH, the builtins, aliases and function definitions.I use
type
andlocate
primarily and only very rarely use the other two since they are relatively limited in capability.Oh, and in order to answer your question,
which
, because it searches $PATH, is more likely to show you the location which will actually run if you type the command "php
". Andtype
is probably going to be even better in cases where you have aliases or functions of the same name since they are executed preferentially over the $PATH location. Note that all of this is system dependent and also dependent on the shell that you are using (my assumption is that it is Bash). On my system, using Bash, the order is functions, aliases, builtins, then $PATH (in the order in which directories are listed there). Compare the output of these various commands to: