Cyprich.com

Occasionally Relevant Insights from a Software Builder

By

Fixing “Error: bad interpreter: No such file or directory” in PHP

I prefer using the PDT tools in Eclipse for working with PHP, but a problem that I keep getting when creating new files is that I can’t execute them in Linux. I get the following error message when I run PHP files from the shell:

Error from PHP document created in Eclipse.

When you get an error like this, the first thing to check is if the interpreter is correct in the PHP source code. This is the first line of text and it looks typically like

#! /usr/bin/php

The PHP interpreter’s path can be found by entering which php in the command shell. Unfortunately, this won’t fix the problem for a PHP document created in Eclipse. The files are being saved as DOS files which you can see if you open your document with vi (see below).

Eclipse created a DOS file.

There is no option in the PDT tools to save files as a UNIX type. The best way to do this is go into the command shell and use the dos2unix command:

i.e. dos2unix test.php

This will convert test.php to a UNIX file type and then it can be executed in the shell. If you view it in vi, the [dos] indicator will not be displayed (see below).

The document is now a UNIX file.

One Response to Fixing “Error: bad interpreter: No such file or directory” in PHP

  1. Underling says:

    Thanks for this. Solved my problem. 😀

Leave a Reply

Your email address will not be published. Required fields are marked *