Some time ago I saw a Sean Coates about not using a hardcoded path to the PHP executable. With the volatile nature of Twitter, I decide to write a blog post repeating his advice.
#PHP developers: the shebang line should be
#!/usr/bin/phpor anything else. My php is likely not where yours is.
— Sean Coates (@coates) February 1, 2012
When you are using PHP for CLI scripts you should avoid starting them with a common shebang like “#!/usr/bin/php”. Not every GNU/Linux distribution or installation method will place the PHP executable in the directory you expect from your own system.
/usr/bin/env can be used to execute commands in a configured environment where the path to the PHP executable (most likely) will appear in the $PATH variable. If it’s not there, it most certainly ain’t in /usr/bin/php.
A much better shebang for your PHP script would be: #!/usr/bin/env php