Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A previously working command line PHP script has stopped working - when i run it now it returns this error:

[root@server dir]# ./custom.php
Extension './custom.php' not present.

If i run the script like this it works:

[root@server dir]# php custom.php

For a number of reasons i cannot do this though. I have read something that implies this could be related to line endings but no idea how/why. i have edited this file recently on A Mac and a PC and FTP'd it to the server but i've been doing that for a long time without issues.

EDIT First line of script is:

#!/usr/bin/php -q

FYI The server is running CentOS 5.4

share|improve this question
please add the script first line – radius Aug 6 '10 at 15:04
up vote 4 down vote accepted

it is generally bad line endings.. using dos line endings. Try using dos2unix on the file and then run it

dos2unix custom.php
share|improve this answer
is there a way i could check what line endings its using to compare to another file? I tend to use Vim if that helps. – seengee Aug 6 '10 at 15:11
dos2unix won't hurt the file.. but generally if you see ^M at the end of lines.. it is that issue – Mike Aug 6 '10 at 15:12
not seeing ^M's at end of line - have seen that before. i'll try dos2unix – seengee Aug 6 '10 at 15:17
seems to have fixed it! thanks :) – seengee Aug 6 '10 at 15:46
He would only see the ^M's at the end of the line if looking at the file on a linux machine using vi. If he looks at the file on a DOS/Windows machine it just looks innocent (unless you use an advanced editor such as Notepad++). – wolfgangsz Aug 6 '10 at 17:18

Put: #!/usr/bin/php in the top of your script (before your PHP-brackets). And then chmod +x custom.php

share|improve this answer
sorry, should have put that in question right away. path to PHP already in there - see Edit – seengee Aug 6 '10 at 15:09

If you edit a php file in windows, upload and run it on linux with command line method. You may encounter a running problem probably like that:

[root@ItsCloud02 wsdl]# ./lnxcli.php

Extension './lnxcli.php' not present.

Or you may encounter some other strange problem. Care the enter key. In windows environment, enter key generate two binary characters '0D0A'. But in Linux, enter key generate just only a 'OA'. I wish it can help someone if you are using windows to code php and run it as a command line program on linux

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.