Tarlan Mamedzadeh Tarlan Mamedzadeh - 1 month ago 11
Apache Configuration Question

Running PHP in Putty gives 'Coud not open input file'

In Putty command line I write

/usr/bin/php /var/www/html/folder/file.php


Also try

php /var/www/html/folder/file.php


Both give 'Coud not open input file'

The permisson for file is 777. Operational system is UNIX

PHP script:

<?php

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: CRON';

mail('admin@website.com','CRON',"<b>THIS IS SIMULATION TEST</b>",$headers);


?>

c4n c4n
Answer

This sometimes happens when you have Windows newline endings (\r\n) instead of Unix style (\n) inside the PHP or cron file.

Fix: convert line endings to Unix style

dos2unix /var/www/html/folder/file.php

or

sed -i 's/\r//' /var/www/html/folder/file.php

or

Use an editor such as Notepad++ to convert EOL:

  1. open the file in Notepad++
  2. double-click "Dos/Windows" in the bottom right corner
  3. change to "UNIX/OSX format"
  4. save, upload and test

.

Remember, do this for both the PHP file and file holding your cron commands.