Set Laravel application online to whole LAN with domain name - php

I have developed a Laravel 5.4 application and now I want to put it "online" for everyone in my LAN and also set a local domain name to it, like somedomain.lan, for example. When I run php artisan serve --port=XXXX it starts the application on localhost port XXXX. Given that I'm running a Linux machine, how to make it available this service on port XXXX in such a way that my whole LAN, and only my LAN (not external internet), sees it and also give the domain name?

Open your command prompt, type "ipconfig", look for your ipv4 address. It should be 192.168.xxx.xxx.
Then php artisan serve --host=[your ipv4 address]
Make other computers connected to your network to connect to your application using your ipv4 address. Your ipv4 address define your computer address within current used network.
Not sure will work or not, but i do it this way and it works.

I would recommend you to use Laravel valet
With valet you can say:
Valet share
Then you will get a unique link that can be shared.
Super easy I use it everyday!
With artisan you can set the ip like this:
php artisan serve --host=503.246.895.41 --port=8125

Related

Laravel sanctum vue spa being blocked when using ip address

I know a lot has been documented on about laravel sanctum configuration to avoid blocked requests from your spa frontend, but something that is not quite clear and people aren't talking about, (maybe because it's already solved and documented somewhere I haven't seen).
My current configuration works with 127.0.0.1 but when I change both SESSION_DOMAIN and SANCTUM_STATEFUL_DOMAINS but when I change this for the ip address, this doesn't work.
I need to use a shared ip (192.168.45.23:8080), for me to test this on my mobile phone as well but I get the net::ERR_BLOCKED_BY_CLIENT.
What is configured so far
I have configured cors.php to allow the route I am visiting under paths
I have SESSION_DOMAIN set to that IP address
I have also set the SANCTUM_STATEFUL_DOMAINS to that IP address with the port as well.
I have also uncommented \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, under the kernel.php
What I am guessing:
Could it be if you not using localhost, you need to be running under https?
The reason I need to use this IP address,
I want to test my spa on mobile concurrently
When you run your Laravel server with this command,
php artisan serve
it will run on localhost and will only receive local connections.
If you want to access to your Laravel server from another machine inside your private network, I suggest you to run this command instead :
php artisan serve --host=0.0.0.0
If you want more detail about the difference between localhost and 0.0.0.0, please read this answer
What I am guessing:
Could it be if you not using localhost, you need to be running under https?
If you use LIVE site deployed on a hosting server, you can access to SPA on your phone.
It will be not handled on Laravel side.
If you wanna test SPA running on localhost using mobile phone,
List item
Run Ngrok to test your local development.
https://ngrok.com
List item
You can use Browserstack Localhost to test localhost on mobile(Emulator). https://www.browserstack.com/docs/local-testing

How to give on local to other pc access to your project in valet?

When I make a project in laravel I can give access with php artisan serve but if a make a normal project and make host with valet link the PHP artisan don't work because it's not a laravel project. How can i give access to local with valet ? For example i have project.dev and make 192.168.1.5:80 like in laravel.
You can use the valet park or valet link commands to be able to access your application locally.
For a local network, you will need to make sure your port is accessible if your're behind a firewall. You may need to setup port forwarding, as well, if NAT is involved.
Are you trying to make the project accessible to others on the internet? For this, you can use ngrok.
https://ngrok.com/
”I want to expose a local server behind a NAT or firewall to the internet.”

ios access localhost from real device

I have a local php(Laravel) server. I can access the domain "mydomain.dev" from an simulator but it does not work when I try to access it from a real device. I have the app running with the device connected to the same wifi network but it still does not work.
Open your command prompt/terminal
Type
windows ipconfig
linux ifconfig -a or ip addr show
write your IPv4 adress
exemple (windows)
Then Run your server php artisan serve or whatever you are using (wamp/laragon or easyphp ..etc)
then go to your browser in your phone and navigate to mydomain.dev
This should work.
Please try to use IP address instead of mydomain.dev. When running on a real device, it will search dns server to look up mydomain.dev. If the dns server can't recognize this url, your device can't open it.

Access Symfony's localhost:8000 on other devices in the same network

I am developing a symfony project on my local machine, I wish to test it on my mobile via IP (both machines connected to wifi network). how do I access port 8000 (symfony's default port) on my mobile phone?
I already know about accessing localhost via IP of the serving device, but I want to access the port too(8000) which I cannot fetch from my devices!
Thanks for all the help
As answered to another Question this might be solved when adding the parameter 0.0.0.0:8000 to let Symfony not only respond to local requests but also accept requests from other devices.
The call then should look something like this:
php bin/console server:run 0.0.0.0:8000
Same way you accessing it from your local machine but using it's IP address e.g.:
http://192.168.1.2:8000
where 192.168.1.2 is your machine IP address in local network (check it using ipconfig command - on Windows or ifconfig on Linux/Mac OS X). Please make sure your firewalls (on local machine and on router) does not block this (8000) port.
UPD: By the way, as far as I remember, Symfony's default port is 8080, not 8000. Please check it carefully.

Access to Laravel 5 app locally from an external device

I've looked for a solution in the web, but I've not found a solution yet.
I need to access to my Laravel 5 app from my iPhone, but I'm in develop, so I don't want to publish my app on a web server.
If you have a link to follow, that you assure it works, It's perfect for me.
Thank you!
If you're not bound to using Apache or nginx for some special reason and this is for development purposes only, you could serve the application using the PHP built-in server and artisan. It's by far the easiest thing to setup, and will only require you to run one command in the Laravel application directory:
php artisan serve --host 0.0.0.0
The default port it will be listening to will be 8000 to avoid any conflicts, so you can now access the application from your phone via the IP address of your computer:
http://192.168.1.101:8000
If you want to listen to another port (for example the default HTTP port of 80) you can pass that as a parameter, just make sure no other server is running on that port. So if you run this instead:
php artisan serve --host 0.0.0.0 --port 80
You can now access your application with just the IP address:
http://192.168.1.101
Its simple, first you have to run the server
php artisan serve --host 0.0.0.0
Then you need to know what`s your IP address, run this command to get IP:
In windows:
ipconfig
In Linux:
hostname -I
For example, my IP is: 192.168.1.68
Once you get your IP, then you have to go to this address on your mobile. Like:
192.168.1.68:8000
And that's it.
There are so many ways to do this.
Access your web via IP address from your iPhone, e.g. http://192.168.1.100/laravel
If your iPhone is jailbroken, you can edit iPhone's /etc/hosts file, the access your website via domain, e.g. laravel.com 192.168.1.100
Upload laravel app to web server and config it a test domain, e.g. dev.domain.com, or dev.domain.com:8080
If you can config your WiFi router, you can give your computer a "port forwarding" or set "DMZ"
Upload your website, and config "IP forbidden" roles, e.g. for Apache, edit your laravel's .htaccess file:
Deny from all
Allow from 180.159.251.175
You can use Laravel Homestead, an official pre-packaged Vagrant "box" to develop your project and access your local website from multiple machines within the same private network.
Here you can find more information about homestead and how to use it:
http://laravel.com/docs/5.0/homestead
And here a sample Vagrant private network setup:
http://docs.vagrantup.com/v2/networking/private_network.html
If you are having trouble using the accepted answers method, and you get page not found or similar errors, this is likely due to your firewall settings.
If
php artisan serve --host 0.0.0.0
doesn't seem to work.
Try php artisan serve --host 0.0.0.0 --port 80.
And access just using your IP address. For instance:
http://192.168.1.101

Categories