search

Home  >  Q&A  >  body text

Codeigniter command line error - PHP fatal error: class 'CI_Controller' not found

After following the instructions in the user guide, I am unable to run the test script via the command line.

My controller is located at /var/www/mysite/application/controllers/

class Tools extends CI_Controller {

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

In the browser I can access

http://mysite/tools/message/ben

This function correctly outputs "Hello ben"

From the terminal, I should be able to run:

$ php index.php tool message "Ben"

My terminal should print out: "Hello Ben"

However, I get the following error:

PHP Fatal Error: Class 'CI_Controller' not found in /var/www/mysite/system/core/CodeIgniter.php line 233

My server is standard ubuntu LAMP. Codeigniter also comes standard and I have no problem running non-CI scripts via the command line.

My PHP is only installed in /usr/bin/php <-- This article hints at problems with running CI directly from usr/bin/php, however I am not using a shared PHP service and don't understand how this would Have an impact on how PHP executes CI scripts.

Thank you very much for your help in advance.

P粉916553895P粉916553895490 days ago818

reply all(2)I'll reply

  • P粉099985373

    P粉0999853732023-09-19 17:02:32

    To resolve the error "Class 'CI_Controller' not found" try going to Application -> Config -> database.php and check the database details like hostname, username, password, and database.

    reply
    1
  • P粉262073176

    P粉2620731762023-09-19 15:50:03

    solved! (Part of the) problem is CodeIgniters error logging.

    In application/config/config.php, I modified the following configuration properties:

    $config['log_threshold'] = 0;

    This will disable logging and allow $ php index.php to execute.

    If anyone can explain why CI only shows this error on CLI PHP - it might help others who run into this issue and need to resolve it via error logging.

    reply
    0
  • Cancelreply