Laravel. How to Use the Integrated Web Server for Local Development


If you want to develop on your computer before you deploy to a real server, Laravel can help. The artisan serve command will spin up a local server, which you can use for quick preview or full fledged development.

To quickly run it you type in your terminal:

php artisan serve

You will now see a confirmation message by Laravel telling you that the server is running.

Laravel development server started:

Point your browser to the following address 127.0.0.1:8000 and you will see your Laravel application running.

Advanced Usage

However working with IPs and ports may not be the ideal solution in some cases. For instance when working with remote services and a domain name is required.

Here is how to start a local server with a domain name and no port. Lets say I want to develop locally on dev.mywebsite.com instead of 127.0.0.1:8000

Step 1. Put a New Entry in your Host File

Open your host file and put a new line in:

127.0.0.1 dev.mywebsite.com

This will tell your machine, that the development website is located on your computer. Test its pointed correctly by pinging the domain

ping tower.dev.sinevia.com

Pinging dev.mywebsite.com [127.0.0.1] with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:
    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
Control-C

2. Launch the Artisan Serve Command with Custom Parameters

To force artisan to server the application on custom domain name and port we will use the --host and --port parameters.

php artisan serve --host dev.mywebsite --port 80

The above command will tell artisan to launch the server with our domain name and listen on port 80. You should see a confirmation message by Laravel.

Laravel development server started:

Point your browser to the following address dev.mywebsite.com and you will see your Laravel application running.

Now you may start working on your application on your computer usng a nice development domain name, test your code locally befor deploying to a live server.