Access to Laravel 5 App Locally from an External Device

Access to Laravel 5 app locally from an external device

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

How can I access my localhost from my physical Android device?

Try this:

php artisan serve --host 0.0.0.0 --port 80

Just make sure that the port is free.

Reference: https://stackoverflow.com/a/30675683/5192105

How can I access my Laravel app from another PC?

Why don't you use Laravel's artisan for it? Very simple:

sudo php artisan serve --host 192.168.1.101 --port 80

Now from other computers, you can type: http://192.168.1.101

Do not forget to replace the IP with your own local one. That's it.

Note: The sudo is only needed if you wanna serve on port 80.

How can i access a second laravel app from another pc

Laravel's artisan serve command uses the PHP Built-in web server. Because that is not a full featured web server, it has no concept of virtual hosts, so it can only run one instance of the server mapped to an IP and port pair.

Normally to serve two hosts from the same IP address you'd add in your VM's /etc/hosts file the following mappings:

192.168.0.60 app.dev
192.168.0.60 demo.dev

Now you can run app.dev by running:

php artisan serve --host app.dev --port 80

And it will be available on your host machine using http://app.dev. However if you would try to spin up a second server instance for demo.dev using this:

php artisan serve --host demo.dev --port 80

It won't work and will complain that:

Address already in use

You could get around that by using a different port for your demo.dev app by using for example this:

php artisan serve --host demo.dev --port 8080

And now you'd be able to access http://demo.dev:8080 for your second app on your host machine.


That being said, I suggest you install a full featured web server such as Apache or nginx and then setup a virtual host for each application (just make sure to keep the mappings from the /etc/hosts file I showcased above).

Setting up virtual hosts can be really easy for both server solutions. Below are links to two articles from the Laravel Recipes website that showcase how to do that specifically for Laravel:

Creating an Apache VirtualHost

Creating a Nginx VirtualHost

Is there a way to access a laravel valet app from another device?

You can give access to everyone to your app by using

valet share

If you want to access it only locally, you can edit you hosts file on your other device and bind the valet URL to your first computer ip

192.168.1.19 laravel.dev

You just have to check if your computer allow remote access.

BTW the valet share command is way more easier :)



Related Topics



Leave a reply



Submit