PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 17, 2022

[FIXED] How do i get the cakephp server command for version 2.1.2

 March 17, 2022     cakephp, cakephp-2.1, cakephp-3.x     No comments   

Issue

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.



Answered By - AD7six
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing