php artisan serve not working with different ports - laravel-4

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

Related

Connect localhost from host virtualbox

I have a Laravel app in Virtualbox in the localhost aka 127.0.0.1:8000 and I want to connect from my host to the server.
Also, it will be great that anyone with the same network can connect to my localhost.
How can this be done?
You can pass the host while running the php artisan serve command.
For example, your network IP is 192.168.1.2
Then run the command like this
php artisan serve --host=192.168.1.2
Hope this will work for you.

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,

How to Access Laravel app from another PC/Phone

I have windows 10 and WSL ubuntu. I used to run
php artisan serve
from my ubuntu(WSL). Now I want to access my laravel app from other devices. Should I run
php artisan serve --host <IP ADDR> --port 80
from ubuntu terminal or should I run it in windows CMD? and which IP should I use? I see different IP from my ubuntu terminal(WSL) as compare to the IP addr from the windows CMD. I don't know what to use.
I already tried to run the code from CMD but I still can't access the app.
You should follow these steps:
1: Run artisan command like this:
php artisan serve --host 0.0.0.0 --port 8000
2: In your other device you should run first your pc IP address and then colon and port number like this:
10.0.56.23:8000

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

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.
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

Resources