Search code examples
cakephpcakephp-2.1cakephp-3.x

How do i get the cakephp server command for version 2.1.2


My present cake project is in version 2.1.2. I want to have a server console command like version 3.x provides. How do I get this working?


Solution

  • A cli is not needed

    cd /path/to/your/app/webroot/
    php -S localhost:8000
    

    Is the equivalent of all the 3.x server command does.

    I want a cli anyway

    Well, the cli is very simple. So all you'd need is to create a command that does the same thing, in principle:

    // app/Console/Command/ServerShell.php
    <?php
    App::uses('AppShell', 'Console/Command');
    
    class ServerShell extends AppShell
    {
    
        public function main()
        {
            $command = sprintf(
                "php -S %s:%d -t %s %s",
                'localhost',
                8080,
                escapeshellarg(WWW_ROOT),
                escapeshellarg(WWW_ROOT . '/index.php')
            );
            system($command);        
        }
    }
    

    Note that this only works with version 5.4+ of php as that's when the inbuilt webserver was introduced.