在 Putty 中运行 PHP 会'Could not open input file'



在Putty命令行中我写

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

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

都给出'Could not open input file'

文件权限为777。操作系统为UNIX

PHP脚本:

<?php
$headers  = 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=utf-8' . "rn";
$headers .= 'From: CRON';
mail('admin@website.com','CRON',"<b>THIS IS SIMULATION TEST</b>",$headers);

?>

当您在PHPcron文件中使用Windows换行符(rn)而不是Unix样式(n)时,有时会发生这种情况。

修复:将行尾转换为Unix样式

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

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

使用编辑器如notepad++转换EOL:

  1. 用notepad++
  2. 打开文件
  3. 双击右下角的Dos/Windows
  4. 更改为"UNIX/OSX格式"
  5. 保存、上传和测试

.

请记住,对于PHP文件和保存cron命令的文件都要这样做。

使用相对路径。也就是说,如果你cd到/var/www/html/文件夹并从那里运行它。

相关内容

最新更新