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:
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
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).
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).