CakePHP cronjob returns 500 error

I have the following entries in my crontab:

SHELL="/bin/bash"
* * * * * /home/peepzcoz/public_html/testapp/bin/cake ClientReminder
* * * * * /home/peepzcoz/public_html/testapp/bin/cake StaffReminder
* * * * * /home/peepzcoz/public_html/testapp/bin/cake ProcessJobRequests

All of these email the result to a mailbox. But for all of them I receive the following message:

Status: 500 Internal Server Error
X-Powered-By: PHP/7.2.8
Content-type: text/html; charset=UTF-8

Debug is switched on in my app.php config file.

If I change the crontab like so:

SHELL="/bin/bash"
* * * * * /usr/local/bin/php /home/peepzcoz/public_html/testapp/bin/cake ClientReminder
* * * * * /usr/local/bin/php /home/peepzcoz/public_html/testapp/bin/cake StaffReminder
* * * * * /usr/local/bin/php /home/peepzcoz/public_html/testapp/bin/cake ProcessJobRequests

I get this result:

################################################################################
#
# Cake is a shell script for invoking CakePHP shell commands
#
# CakePHP(tm) :  Rapid Development Framework (https://cakephp.org)
# Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
#
# Licensed under The MIT License
# For full copyright and license information, please see the LICENSE.txt
# Redistributions of files must retain the above copyright notice.
#
# @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
# @link          https://cakephp.org CakePHP(tm) Project
# @since         1.2.0
# @license       https://opensource.org/licenses/mit-license.php MIT License
#
################################################################################

# Canonicalize by following every symlink of the given name recursively
canonicalize() {
        NAME="$1"
        if [ -f "$NAME" ]
        then
                DIR=$(dirname -- "$NAME")
                NAME=$(cd -P "$DIR" > /dev/null && pwd -P)/$(basename -- "$NAME")
        fi
        while [ -h "$NAME" ]; do
                DIR=$(dirname -- "$NAME")
                SYM=$(readlink "$NAME")
                NAME=$(cd "$DIR" > /dev/null && cd $(dirname -- "$SYM") > /dev/null && pwd)/$(basename -- "$SYM")
        done
        echo "$NAME"
}

CONSOLE=$(dirname -- "$(canonicalize "$0")")
APP=$(dirname "$CONSOLE")

if [ $(basename $0) != 'cake' ]
then
    exec php "$CONSOLE"/cake.php $(basename $0) "$@"
else
    exec php "$CONSOLE"/cake.php "$@"
fi

exit

If I run it directly in the terminal, it executes fine and all of them do what they are supposed to.

How can I get debug output so that I atleast know what the issue is? I can’t see error logs on this server and the error logs in the cake logs folder is empty.

What else can I check?

Why you don’t try to use curl method. Simply create a method and call that URL by curl. Make sure your method must be allowed.

Okay so I solved the problem by downloading the newest version of bin/cake. But it wasn’t that simple.

Firstly, I downloaded it to my windows machine and then uploaded it to the server, which changed the line endings to windows line endings. This caused a new error:

/usr/bin/env: sh
: No such file or directory

So I tried to run dos2unix bin/cake, but dos2unix wasn’t installed on the shared server.

I solved this by doing a wget on the raw file and overwriting the bin/cake file. This solved it and my crons started running.

A little off topic, but you can view debug information by adding DEBUG=1 to your cronjob:

* * * * * DEBUG=1 /home/peepzcoz/public_html/testapp/bin/cake ClientReminder

I know that you solve this, but cron jobs can be launched as a root or other user that you use in terminal and maybe there is something with PATH or executable rights.