Search code examples
laravellaravel-4php-5.4

Set port for php artisan.php serve


How do we set a custom port for test server?

Normally when we do

php artisan serve

the folder gets served as :

localhost:8000

How do could we access one folder as:

localhost:8080

I want to access two different development sites on my localhost.


Solution

  • Laravel 5.8 to 8.0 and above

    Simply pass it as a paramter:

    php artisan serve --port=8080
    

    You may also bind to a specific host by:

    php artisan serve --host=0.0.0.0 --port=8080 
    

    Or (for Laravel 6+) you can provide defaults by setting SERVER_PORT and SERVER_HOST in your .env file. You might need to do php artisan cache: clear as well. (thanks @mohd-samgan-khan)

    And if you want to run it on port 80, you probably need to sudo.