How to add shebang #! with php script on linux?

I'm having a little issue with adding shebang #! with my php script on RedHat linux. I have a small piece of test code with shebang added (I've tried different variations as well), but I get the following error message everytime I try to run the script.

Error msg:

-bash: script.php: command not found

Test script:

#!/bin/env php    
<?php echo "test"; ?>

Shebang #! variations:

#!/usr/bin/env php


It should (for most systems) be #!/usr/bin/env php, but your error isn't related to that.

-bash: script.php: command not found

It says that script.php is not found.

If the problem was the shebang line then the error would say something like:

bash: script.php: /usr/env: bad interpreter: No such file or directory

Presumably, you are typing script.php and the file is not in a directory on your $PATH or is not executable.

  1. Make it executable: chmod +x script.php.
  2. Type the path to it instead of just the filename, if it is in the current directory then: ./script.php.

Instead of 2, you can move/copy/symlink the file to somewhere listed in $PATH or modify the $PATH to include the directory containing the script.

If you script is not located in your /usr/local/bin and is executable, you have to prefix calling your script with php like this:

php myscrip.php

For shebangs, here is what I use:

Like this:


or this:

#!/usr/bin/env php

Need Your Help

Make HTML5 video poster be same size as video itself

css html5 attributes html5-video

Does anyone know how to resize the HTML5 video poster such that it fits the exact dimensions of the video itself?

Why is it OK to return vector from function?

c++ vector stl scope standard-library

Please consider this code. I have seen this type of code several times. words is a local vector. How is it possible to return it from a function? Can we guarantee it will not die?