How to Access Laravel app from another PC/Phone - laravel

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

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,

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