Php – Why is crontab giving “No such file or directory” error when the file DOES exist

cronPHPunix

I am getting the following three lines in an error message in /var/mail/username after the following job runs in crontab…

15 * * * * /Applications/MAMP/htdocs/iconimageryidx/includes/insertPropertyRESI.php

Errors:

/applications/mamp/htdocs/iconimageryidx/includes/insertpropertyRESI.php: line 1: ?php: No such file or directory
/applications/mamp/htdocs/iconimageryidx/includes/insertpropertyRESI.php: line 3: syntax error near unexpected token `'initialize.php''
/applications/mamp/htdocs/iconimageryidx/includes/insertpropertyRESI.php: line 3: `require_once('initialize.php');

The PHP script I am trying to execute DOES in fact exist, and I have made absolutely sure the spelling is correct several times. I ran a crontab on another script before and it worked just fine…any ideas??

The 2nd & 3rd Errors are from line 3 in the following script (the one I am trying to run with the crontab):

<?php
    require_once('initialize.php');
    require_once('insertPropertyTypes.php');

    $sDate;
    if(isset($_GET['startDate'])) {
        $sDate = $_GET['startDate'];
    } else {
        $sDate = '';
    }

    $insertResi = new InsertPropertyTypes('Listing', $sDate, 'RESI');
?>

When I run my script insertPropertyRESI.php in the browser, it runs just fine???? Also, initialize.php and insertPropertyTypes.php are in the same directory as insertPropertyRESI.php

I am using MAMP with PHP 5.3.5

thakns for the help 😕

Best Answer

You are trying to execute a script which does not have a valid shebang.
Add the shebang as the first line of the script like this (adjust path of course):

#!/usr/bin/php

Or change the crontab entry to:

15 * * * * /usr/bin/php /Applications/MAMP/htdocs/iconimageryidx/includes/insertPropertyRESI.php