[ACCEPTED]-CodeIgniter : Run a script from command line if the controller is inside a folder?-codeigniter-2

Accepted answer
Score: 16

You can try with :

php index.php myFolder myController myFunc myParam1 myParam2 ...


Score: 1

Note, the index method in class file is 2 necessary for work properly in CLI, otherwise 1 codeigniter will return 404 error.


Score: 1

For CodeIgniter 1.7 (if someone is unlucky to have to support 18 a legacy project), there is a solution mentioned 17 here:

Running CodeIgniter from the Command Line

The Goal

Just like the title says, our goal is 16 to be able to run CodeIgniter applications 15 from the command line. This is necessary 14 for building cron jobs, or running more 13 intensive operations so you don't have the 12 resource limitations of a web script, such 11 as maximum execution time.

This is what it 10 looks like on my local Windows machine: Screenshor from the original post

The 9 above code would be like calling this URL:


The Hack

Create 8 a "cli.php" file at the root of 7 your CodeIgniter folder:

if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Command Line Only!');



require dirname(__FILE__) . '/index.php';

If you are on a 6 Linux environment and want to make this 5 script self executable, you can add this 4 as the first line in cli.php:


If you want 3 a specific controller to be command line 2 only, you can block web calls at the controller 1 constructor:

class Hello extends Controller {

    function __construct() {
        if (isset($_SERVER['REMOTE_ADDR'])) {
            die('Command Line Only!');

    // ...


More Related questions