How to use the Laravel’s php artisan serve Command

How to use the Laravel’s php artisan serve Command

Demonstrate how to start the Laravel development server with the php artisan serve command.

Introduction

In this article, i demonstrate what the php artisan serve command does and how it is used in a Laravel 11 application during local development.

The command line interface called Artisan exists at the root of the application as the artisan script and contains helpful commands to build and interact with different parts of the application.

💡
If you’re familiar with php artisan serve command. You can checkout this video on my Youtube channel where i explained how to create custom artisan commands in Laravel

I’ve a video on my Youtube channel where i explained how to create custom commands in Laravel

What is php artisan Serve

The php artisan serve command in Laravel is the basic command used to start a Laravel development server during local development. This command is used for serving both API and fullstack Laravel application during local development.

How to use the php artisan serve command

The command below can be executed at the root of the Laravel application in any terminal of your choice to serve the application.

php artisan serve

This will start a development server @ http://127.0.0.1:8000 by default

How to customize the Host and Port of the server

There are several arguments that can be added to the php artisan serve command to customize it.

  • Custom Port

Use the —port flag to start the Laravel server on a port other than 8000

php artisan serve --port=8001
//or
php artisan serve --port=8002
  • Custom Host

Use the —host flag to specify a custom host for the Laravel application

php artisan serve --host=127.0.0.2

The —host and —port flag can be used on the command

php artisan serve --host=127.0.0.2 --port=8001

How to Terminate the server

You can close the terminal session or press ctrl + c to terminate the server

💡
The Laravel local development server will not be reachable once the server stops running.

Conclusion

In this article, we’ve explore a simple artisan command that is used to quickly start the development server of a Laravel application locally.

Find this article useful… kindly share with your network and feel free to use the comment section for questions, answers, and contributions.

💡
Follow me on Hashnode: Alemsbaja --- X: Alemsbaja ---- Youtube: Tech with Alemsbaja to stay updated on more articles

Did you find this article valuable?

Support Alemoh Rapheal Baja by becoming a sponsor. Any amount is appreciated!