Set port for php artisan.php serve
Asked Answered
S

10

216

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.

Schulein answered 1/8, 2013 at 9:57 Comment(1)
php artisan serve --help will show the usage and options. --help is available on every artisan command.Denby
B
429

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.

Bonded answered 13/11, 2013 at 3:35 Comment(7)
is there anyway to set this as the default?Zodiac
@Zodiac Not that I know of, unless you modify the source code itself. I guess you could write a custom command to wrap the serve command with your preferred arguments: laravel.com/docs/5.4/artisanTuberculate
Yes. Its working for me php artisan serve --port=8001Savitt
Yes there is, as of Laravel 6: set SERVER_PORT in your .env file. https://mcmap.net/q/128392/-how-to-change-default-url-from-localhost-8000-to-other-ip-in-laravel-when-we-run-quot-php-artisan-serve-quotBroderickbrodeur
@Broderickbrodeur that's correct, I've updated the answerTuberculate
This solution works for laravel v8 as wellPrent
SERVER_PORT, works but please dont forget to run cache:clean as this is read directly from env not from the cache.Fecula
A
48

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

php artisan serve --host=0.0.0.0 --port=8000
Animism answered 18/4, 2017 at 0:28 Comment(1)
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!Smothers
B
15

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

Blowy answered 1/8, 2013 at 13:42 Comment(0)
C
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
Cofer answered 26/3, 2019 at 10:39 Comment(1)
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.Factual
H
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.

Howlond answered 13/12, 2014 at 21:42 Comment(0)
L
6

You can use

php artisan serve --port 80

Works on Windows platform

Laurenalaurence answered 14/4, 2017 at 20:54 Comment(0)
L
5

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

php artisan serve --host=172.10.29.100 --port=8080
Lehman answered 4/2, 2020 at 17:37 Comment(0)
S
2
sudo /Applications/XAMPP/xamppfiles/bin/apachectl start

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

Shaggy answered 22/4, 2019 at 23:12 Comment(0)
D
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

Doddered answered 4/3, 2020 at 16:34 Comment(0)
C
0

Laravel Framework 11.0.8

As mentioned in the sail file: ./vendor/laravel/sail/bin/sail

# Open the site...
#...
#...
        if [[ -n "$APP_PORT" && "$APP_PORT" != "80" ]]; then
            FULL_URL="${APP_URL}:${APP_PORT}"
        else
            FULL_URL="$APP_URL"
        fi
#...
#...

1- Open the .env file and add the following code:

APP_URL=http://localhost
APP_PORT=8001

2- then run it :

./vendor/bin/sail build --no-cache
./vendor/bin/sail up -d // or ./vendor/bin/sail up
Congou answered 26/3 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.