Set port for php artisan.php serve - laravel

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.

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.

as this example you can change ip and port this works with me
php artisan serve --host=0.0.0.0 --port=8000

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

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

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.

You can use
php artisan serve --port 80
Works on Windows platform

you can also add host as well with same command like :
php artisan serve --host=172.10.29.100 --port=8080

sudo /Applications/XAMPP/xamppfiles/bin/apachectl start
This fixed my issue AFTER ensuring my ports were all uniquely sorted out.

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

Related

Laravel web root path - where is it

I installed laravel at /var/www/laravel on Ubuntu
Can you please tell me how to access the laravel framework from browser ?
Go to /var/www/laravel directory and run the command php artisan serve
The artisan command is just a command-line utility for Laravel. The serve command just starts up the PHP server, which you can do yourself as well with PHP -S 8080 (which would start a PHP web server (single-threaded) in the current directory on port 8080)
If you want to define the host ip then use below command to set host and port
php artisan serve --host=<host IP address> --port=<port to use>
php artisan serve --host=127.0.0.1 --port=8080
If you want to access a simple way without serve command.
server_ip/projectname/public
you'll see the your home page there,

Run localhost/laravel/public/my_page the result is just a blank page without any error

I have a Laravel project, all pages run fine if using php artisan serve, but some pages can not run without artisan serve.
Example when I access localhost:8000/my_page my page is loaded fine. But when I run localhost/laravel/public/my_page
the result is just a blank page without any error.
By default localhost/laravel/public/my_page uses port 80 but Laravel is only listening to port 8000, localhost:8000/my_page works because is telling your browser to use port 8000 instead of the default port of 80.
Try running php artisan serve --port=80 if you do not have another service already running on port 80 or if your firewall does not block the port then you should be able to use localhost/laravel/public/my_page

Command php artisan serve on other network?

I know that when i run this command:
php artisan serve --host=localhost
It works when other computer is on same network, but if someone from other network wanna access it is it possible? Im asking that because i can not check at the moment.
Apart from setting correct rules for firewall and router you need to run the command with a reacheble host, i.e:
php artisan serve --host 0.0.0.0
or better to be explicit with your IP address
php artisan serve --host YOUR_IP_HERE
On Ubuntu 18 in Virtualbox I just needed
sudo ufw allow 8000
for the additional firewall rule and then
php artisan serve --host=_your_ip_address
Now it works on every device in the network.
Thanks to this Laracast Discussion.
Sometimes php artisan serve may fail you can just use the built in php server like this
php -S <ip-to-remote-serve>:<port> -t public public/index.php
for example
php -S 192.168.100:8000 -t public public/index.php

How i can remove port number in url

I am using laravel framework in ubunto system and I want to remove port number from my url
write now I can access my web-project with this url
http://localhost:8000
and I want this url
http://localhost/
How can I do this?
80 is the default port number of http so you have to use this command to omit the port number:
sudo php artisan serve --host=localhost --port=80
You can try
sudo php artisan serve --port=80
If nothing else (e.g. Apache oder Nginx) uses port 80 you COULD start the development webserver like this
sudo php artisan serve --port 80
You can access the app via http://localhost/ afterwards
Note that this is ONLY for development and some kind of hack. Install a dedicated webserver (Apache, Nginx) for production :-)
Do not use php artisan server in your commandline and use full URL path in browsers address bar as follows
http://localhost/projectname/public

php artisan serve not working with different ports

When I type in
php artisan serve --host test.com
I got this error
[Wed Jan 14 12:54:12 2015] Failed to listen on test.com:8000 (reason: Can't assign requested address)
so I tried
php artisan serve --host test.com --port 8080
and I still got the same error just the port number is different. And it's the same with every number I can think of.
You're trying to assign a port on another server, to get around this you can either add that domain into your "hosts" file, or use a port on localhost.
1. Add to "hosts" file
On most linux distributions it's here: /etc/hosts and on mac: /private/etc/hosts.
You should add a new line following the format of the other lines in the file. Assign the IP of localhost (127.0.0.1) to that domain like so:
127.0.0.1 test.com
Now you will be able to open ports on localhost, using test.com:
php artisan serve --host test.com --port 8080
...and now you can access your app, in your browser via: http://test.com:8080.
2. Use localhost
Alternatively just assign a port on locahost:
php artisan serve --host localhost --port 5000
and access in your browser via: http://localhost:5000
sometimes your IP address get changed so first go to command prompt and type ipconfig there ipv4 address will be listed copy it and the go to terminal type php artisan serve --host youripaddress. Cheers
Use php artisan serve --port='YOUR-PORT' command.
or
you can create a variable SERVER_PORT in your .env file
Example:
SERVER_PORT=80

Resources