Tobias Gassmann Tobias Gassmann - 6 months ago 40
Bash Question

PHP Shebang not working

NOTE: This question has been solved. It is a duplicate of shebang line not working

This is what I have:

#!/usr/bin/env php
echo "starting";

The file is executable "-rwxr-xr-x"

I call the file with its complete path


But I only get the error-message ": No such file or directory"

Calling the script with

php /var/projects/user-backup.php

results in the String "Starting..." being displayed as expected.

Even when I try to

/usr/bin/env php /var/projects/user-backup.php

everything works out fine, the String "starting..." is displayed as expected.

Where am I going wrong?

Using shebang like this:


results in the Error-message "^M: bad interpreter: No such file or directory"
although there definitely is a /usr/bin/php (/usr/bin/php -> /etc/alternatives/php , and /etc/alternatives/php -> /usr/bin/php5)


I think I've got it (thanks to EDIT1):

Your php file has Windows style line endings (EOLN s); In Windows, EOLN is \r\n (\x0D\x0A), while on Unix is \n (0x0A). Some Unix interpreters don't like \r, and this is the case here.

To make things work convert your EOLN s to Unix style:

dos2unix /var/projects/user-backup.php