How to share laravel app in local network - php

I have developed a laravel application and I want to share this application in my local network to be able to access to this app from any workstation connected to this network.
I'm using EasyPHP-Devserver-17 and the app is working correctly on the local machine (127.0.0.1/app/public). I have changed the phpserve file to add "Listen 10.0.102.2:8080" and once I add this to phpserve file I can access to this address "http://10.0.102.2:8080" from others workstation, but when I go to the laravel app I got this error message:
Not Found
I changed the URL in the following files in the laravel app: app.php, .env and livewire.php, but I still get the same error message.

hello maybe this link will serve you
Access to Laravel 5 app locally from an external device
php artisan serve --host 0.0.0.0 --port 80
"0.0.0.0" is your ip server
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

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

Set Laravel application online to whole LAN with domain name

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

Use local apache API from Laravel

I have developed an API which is available locally on loc.api and on production on live.api (obviously the domains are just an example).
The API runs locally on a classic apache server.
Now I am playing with Laravel, using this API. No problem connecting to live.api (as I am using the real domain), but fails to connect to my local API.
I am guessing it is just a host config issue, as Homestead fails to connect to my normal apache server on my cumputer.
If that is the case, I should just have to define an IP linked to loc.api, but I have no idea what IP I should use there.
So to recapitulate, no problem running loc.api on my local apache server, no problem running live.api, no problem running Laravel on its own or connected to live.api, but can't seem to get Laravel to work with my loc.api
Any ideas ?
Homestead runs on something akin to a virtual machine. The virtual machine's localhost is indeed the local IP address used internally within the virtual machine. In order to communicate with the host machine (the machine running the virtual machine) you need to use the default gateway IP address. This is the IP address which the virtual machine uses to refer to its host system.
The default varies depending on the configuration of the virtual machine. Ideally, if you've setup your API normally on your localhost and access it locally via 127.0.0.1 (or localhost) then setting your local site configuration to the default gateway will work.
However, if you set up your API through a virtual host and you access it via local.api or some host like this you need to modify your virtual machine's /etc/hosts file (since homestead is serving an Ubuntu OS) and enter a line like
<gateway IP> local.api
This way you can use local.api as your API host address which will resolve to the gateway IP and call the API using the correct hostname.

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

Cannot connect to Laravel server in Virtual Box appliance

I am trying to implement my first Rest API using Laravel.
I am running Debian on a Virtual Box machine on a Windows host. The network card of the VM is configured to "Host-only adapter".
I am able to reach the phpmyadmin instance on the machine using http://ip-of-the-vm/phpmyadmin. But when I try to reach the Laravel appliance on http://ip-of-the-vm:8000 it does not work. I think the port could be the problem.
Does anybody have a suggestion for how to solve this?
The problem was that laravel was only reachable over localhost. You have to start the server using
php artisan serve --host 0.0.0.0 where 0.0.0.0 should be replaced with the ip of the server.
You can optionally define a port if you want by using
php artisan serve --host 0.0.0.0 --port 80 for example.

Categories