210

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.

Andreas Bergström
  • 13,891
  • 5
  • 59
  • 53
maan81
  • 3,469
  • 8
  • 36
  • 53
  • `php artisan serve --help` will show the usage and options. `--help` is available on every artisan command. – None Feb 24 '20 at 23:03

11 Answers11

414

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.

Andreas Bergström
  • 13,891
  • 5
  • 59
  • 53
47

as this example you can change ip and port this works with me

php artisan serve --host=0.0.0.0 --port=8000
Ahmed Mahmoud
  • 1,724
  • 1
  • 17
  • 21
  • I'm running a test server on AWS / EC2. (instead of my local). So dropped this code into the terminal and I'm up and running! – Chad Jul 05 '17 at 16:48
15

One can specify the port with: php artisan serve --port=8080.

Rob Gordijn
  • 6,381
  • 1
  • 22
  • 29
14

You can use many ports together for each project,

  php artisan serve --port=8000

  php artisan serve --port=8001   

  php artisan serve --port=8002

  php artisan serve --port=8003
Shabeer K
  • 1,489
  • 16
  • 23
  • I ran multiple laravel projects on different ports.It gives 404 not found error. Do I have to configure the port in somewhere else also. – Eranda Peiris Jan 20 '21 at 04:58
6

Andreas' answer above was helpful in solving my problem of how to test artisan on port 80. Port 80 can be specified like the other port numbers, but regular users do not have permissions to run anything on that port.

Drop a little common sense on there and you end up with this for Linux:

sudo php artisan serve --port=80

This will allow you to test on localhost without specifying the port in your browser. You can also use this to set up a temporary demo, as I have done.

Keep in mind, however, that PHP's built in server is not designed for production. Use nginx/Apache for production.

Derrek Bertrand
  • 596
  • 7
  • 13
6

You can use

php artisan serve --port 80

Works on Windows platform

vishal pardeshi
  • 334
  • 4
  • 14
5

you can also add host as well with same command like :

php artisan serve --host=172.10.29.100 --port=8080
Ashish Patel
  • 1,011
  • 13
  • 27
2
sudo /Applications/XAMPP/xamppfiles/bin/apachectl start

This fixed my issue AFTER ensuring my ports were all uniquely sorted out.

Dr Tyrell
  • 125
  • 8
2

when we use the

php artisan serve 

it will start with the default HTTP-server port mostly it will be 8000 when we want to run the more site in the localhost we have to change the port. Just add the --port argument:

php artisan serve --port=8081

enter image description here

Thilina Dharmasena
  • 2,243
  • 2
  • 19
  • 27
1

Run this command in CMD to run the Laravel project on different port.

php artisan serve --port=8080
0

Open the terminal in your project directory and write this command:

php artisan serve --port=8080

Laravel development server started: HTTP://127.0.0.1:8080