• 4
name Punditsdkoslkdosdkoskdo

Commands line PHP scripts no longer working

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

I am also getting the problem that when the PHP file executed in the shell, the init.php's code is being returned almost as text in the shell rather than being processed as a PHP script.

This sounds like you don't have short tags enabled.

When running through CLI, PHP can be using different php.ini than it does under Apache. Run php -i to determine the config file(s) it is using, then edit the appropriate config file to enable short tags.

  • 0
Reply Report

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

  • 0
Reply Report

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

dos2unix custom.php
  • 4
Reply Report