Search code examples
phpcodeignitercroncpanelshared-hosting

Not working shared hosting cPanel cronjob under Codeigniter


Despite there are many posts with a similar topic, I couldn't find anyone matching my case that I briefly describe here. This is the testing script

    <?php

    if (!defined('BASEPATH')) exit('No direct script access allowed');
    require 'DashboardBase.php';

    class Hello extends CI_Controller {

            public function message($to = 'World')
            {
                    echo "Hello {$to}!".PHP_EOL;
                    print "Hello {$to}!".PHP_EOL;
                    log_message('error',"Hello {$to}!".PHP_EOL);
            }
    }

    ?>

The web server is under a shared hosting; it is used cPanel; Codeigniter is used.

The external URL that works properly is this: https://pharmacomparison.com/adminPanel/hello/message/federico

I have activated the cronjob output notification on my personal email and it can be noted that I also save the output in an error log.

Here my cronjob definition attempts

  1. (as suggested by CodeIgniter manual): /usr/local/bin/php public_html/adminPanel hello message "federico" --> no email notification; no output in the 'error' log

  2. small modification, added a "/": /usr/local/bin/php public_html/adminPanel/ hello message "federico" --> no email notification; no output in the 'error' log

  3. (supposed wrong in advance, but let's try) /usr/local/bin/php public_html/adminPanel/hello message "federico" --> email notification reporting "Could not open input file: public_html/adminPanel/hello"; nothing in 'error' log

  4. (supposed wrong in advance, but let's try) /usr/local/bin/php public_html/adminPanel/hello.php message "federico" --> no email notification, in 'error' log "ERROR - 2020-01-10 16:09:25 --> 404 Page Not Found: Hellophp/message"

  5. full real disk path: notification email reporting "No direct script access allowed"

Basically, the first two attempts supposed correct generate nothing even no errors. Any ideas?


Solution

  • You are not running it correctly, here is how to run a function in codeigniter through CLI.

    Please try this

    php /usr/local/bin/php public_html/adminPanel/index.php Hello message "federico"

    All function calls must go through index.php

    php /path_to_project_root/index.php ControllerName function "argument"