// you’re reading...

Tips N Tricks

Solved: Extension filename.php not present

The day was pleasant till I got an E-mail from a client with a PHP script file attached to it. I had to schedule the PHP script via Cron on a Linux server. For PHP scripts in Cron, I do not prefer writing the Cron job as:

1  30  *  *  *  /usr/bin/php -q /opt/script.php

Instead, I prefer a crisper line as:

1  30  *  *  *  /opt/script.php

The latter is obviously neater and readable. To prepare a PHP script to execute just by the filename, you need to do two things:

  1. Add a line to the path to the PHP interpreter at the top of the script. For example:
    #!/usr/bin/php -q
    // PHP code          
  2. Make the script executable as:
    chmod + script.php

Before inserting it in Cron it is always a good idea to test the script by executing it manually as:


What always worked for me, failed on me this time with an error saying: Extension /opt/script.php not present. What will you do when you get an informative error (being sarcastic) like this? I too had no clue.I checked the path of the PHP interpreter, double checked the permissions and also found other PHP files to be working. The script worked when served via a Web Server (Apache). What added to the confusion was, the same script worked when executed as follows:

/usr/bin/php -q /opt/script.php

I could have wasted hours in troubleshooting this if it hadn’t clicked to my mind that the client who sent me this script uses Windows. This means, this script would have been written in one the Windows text editors. Going by experience, case insensitivity and newline characters is the root to most problems with script which are written in Windows and run on Linux. A quick check did not reveal any case related issue.

To fix the second possible problem, I used dos2unix – a handy commandline tool to convert Windows based text files into Linux files (more on this later).

dos2unix /opt/script.php

And voila! this fixed the problem. I was then able to execute the script as /opt/script.php and also scheduling it via Cron worked perfectly.

If you ask me, how exactly did Windows newline characters would have messed up the script to result into this cryptic error (Extension script.php not present), I don’t have an answer. But going by the above fix, it was definitely Windows newline characters which were causing the problem.

A note about Windows and Linux newline character: Windows uses \r\n as the new line or next line characters. \r is called the carriage return character and \n is called the line feed character. Whereas in Linux, \n (line feed) is the newline character. The command line tool called dos2unix replaces all the \r\n (carriage return and line feed pair) to \n (line feed) in a script or text file.

GD Star Rating
GD Star Rating
Solved: Extension filename.php not present, 9.9 out of 10 based on 7 ratings

Email This Post Email This Post Print This Post Print This Post Print This Post Post A Comment Tweet your comments/question to me @shekharg


4 comments for “Solved: Extension filename.php not present”

  1. Hi,

    Just to let you know that after two days searching on the Web for a solution to my PHP script Mail piping. You post made it work ( Windows vs Unix End of Line)

    When running my email piping parsing PHP script from Cron , the message I had was:

    ” A message that you sent could not be delivered to one or more recipients. This is a permanent error. The following(s) address(es)failed:”

    Using using GEDIT (freeware) a have “converted” my PHP script file to Unix type End Of line

    GEDIT Windows version link:


    Hope that will help some other fellows loosing their time troubleshooting the invisible.


    Posted by Real | July 25, 2011, 7:40 pm
  2. Thanks a bunch, this was a HUGE help!

    Posted by SpirytSista | April 7, 2012, 6:12 am
  3. Thank you very much!
    I use Dreamweaver, i just tried open same file on the server directly and save again. It worked!

    Posted by Alan | February 16, 2014, 11:03 am
  4. Thanks … saved a ton of time with this information!

    Posted by Kevin | August 22, 2016, 11:59 pm

Post a comment

Recent Tweets

Follow Me on Twitter