Command php artisan serve on other network? - laravel

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

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