Posts Learn Components Snippets Categories Tags Tools About
/

How to set Port Number for php artisan serve Command in Laravel

Learn how to set up the port number of "php artisan serve" command line in your Laravel project to have different number and possibly prevent conflict with your existing running application.

Created on Oct 29, 2021

4049 views

To set the "php artisan serve" command port number to anything other than 8080 you can specify the port number using the "--port" flag and then specify the port number.

Specify Port From Command Line


You can write your code like below.
php artisan serve --port=9000
For the host, if you are not using localhost or 127.0.0.1 you can pass in the "--host" flag as well.
php artisan serve --host=127.0.0.2

Specify Port From Configuration File


The 2nd method is to specify the port from the configuration file or right away export it from the terminal and you can write it like the following.
Specify the file definition inside the .env environment file.
# .env file
SERVER_PORT="9000"
Or terminal export definition.
export SERVER_PORT="9000"
Then after you have done that you can right away call the artisan serve command like you normally would.
php artisan serve

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

)