How to Run Laravel Development Server on a Different Port

In laravel on 1~3 minutes
How to Run Laravel Development Server on a Different Port

Normally, the development server of the Laravel runs on port 8000, which can be accessed from http://localhost:8000. But there are situations where you need to run multiple instances of Laravel applications at the same time on the same development PC. Under that kind of situation, it will not be able to start the second application as they have to use the same port 8000. So for that kind of situation, we need to use a separate port instead of the default port.

We use the Laravel Artisan command php artisan serve to start a development server. We can add the --port to mention a specific port we need to run the application. For example, if we need to run the application on port 8080 instead of the default port 8000, we can use the following command.

php artisan serve --port=8080

Now if you need to start another instance of the Laravel application, you can change the port of the serve command to another unused port.

If you do not like to mess with the serve command to change the port like that, you can still change the default port by using the .env file. Open the .env file in the root directory of the application and add the following line to it.

SERVER_PORT=8080

Now you can start the Laravel development server as you used to be by just using the usually php artisan serve command and it will start the development server with the port number you mentioned in the .env file.