Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set port for php artisan.php serve

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.

like image 808
maan81 Avatar asked Aug 01 '13 09:08

maan81


People also ask

How do I serve a Laravel project on a different port?

We can run the laravel project using "php artisan serve" command. It will use by default 8000 port to run the laravel app. But you want to run laravel project on a different port then the artisan command provides an option called "--port" and you can run the laravel app in a different port.

What port does Laravel run on?

Normally, the development server of the Laravel runs on port 8000 , which can be accessed from http://localhost:8000.

How do I run artisan serve in php?

In Laravel, we can run Laravel Development server by typing php artisan serve command on terminal or command line. Make sure your in Laravel's project root directory. If not change your present working directory.

What is php artisan serve command?

The Laravel PHP artisan serve command helps running applications on the PHP development server. As a developer, you can use Laravel artisan serve to develop and test various functions within the application. It also accepts two additional options. You can use the host for changing application's address and port.


2 Answers

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.

like image 117
Andreas Bergström Avatar answered Sep 28 '22 00:09

Andreas Bergström


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

php artisan serve --host=0.0.0.0 --port=8000 
like image 38
Ahmed Mahmoud Avatar answered Sep 27 '22 23:09

Ahmed Mahmoud