13

So, i try to install the lumen restful api. Based on tutorial, i have to "serve" on php artisan. The command be like:

php artisan serve sample_api sample_api/public

then it shows:

Command "serve" not defined.

Some say that serve command has been deleted in laravel 5 (which i use it). if so, what command should i use? or maybe find another tutorial?

Ps: Im a newbie :)

Thanks a lot!

patricus
  • 59,488
  • 15
  • 143
  • 145
apapipip
  • 139
  • 1
  • 1
  • 3

3 Answers3

48

You can use

php -S localhost:8080 -t public/
  • 1
    In windows, you can also make a .bat/.cmd with the command in the answer and name it like `serve.bat`, then you can run it from windows cmd. :) – Ciberman Sep 04 '16 at 19:04
3

This command was removed from Lumen 5.2. You can use any other web server to run your app. I'd recommend to learn Homestead with built-in environment. If you're newbie, you can use something like WAMP.

Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
  • I can't believe how docs are outdated and there is no example how to run it on plain apache (must use virtual host). Damn. – Andrey Popov Sep 28 '16 at 17:46
0

Although there is no artisan make:command in Lumen, you can follow this procedure to reimplement artisan serve, or even use it as a template to create other console commands.

The serve command was removed since Laravel Lumen 5.2, but you can reimplement it manually as it follows:

Get the ServeCommand.php file from Lumnen 5.0, save it to the folder app/Console/Commands and perform these 2 tweaks:

  1. Change the namespace from Laravel\Lumen\Console\Commands to App\Console\Commands.
  2. Rename the function fire to __invoke.

Edit the file app/Console/Kernel.php to tell artisan the existence of this new command by listing it in the $commands member, like so:

    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        Commands\ServeCommand::class,
    ];

After doing that, you should be able to run artisan serve. Notice that it will be serving a file server.php from your project root folder. You need to create this file, or change the code to serve something else.


Paulo Amaral
  • 747
  • 1
  • 5
  • 24