Thursday, April 11, 2024

How to make php artisan to run on different port

When we want to run two servers on the same machine we may need to have two different ports.  We can change the default port for the Artisan development server by two ways.
        1. Changing the port number in env file.
        2. Through port argument to php artisan command.

1. .Env file change: 
        you can add the parameter SERVER_PORT to the .env file in the root directory of your project. Then, you can use the command php artisan serve to start the server with the new port. The default port is 8000, but serve will scan up to port 8009 for available ports

2. Passing argument to the command
        We can pass the --port argiment to php artisan serve command and run it to start the localhost server on the specified port
        php artisan serve --port:8080

       
Artisan Serve Improvements

In previous releases of Laravel, Artisan's serve command would serve your application on port  8000. If another serve command process was already listening on this port, an attempt to serve a second application via serve would fail. Beginning in Laravel 5.8, serve will now scan for available ports up to port 8009, allowing you to serve multiple applications at once.

No comments: