66

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!

Alex Kyriakidis
  • 2,861
  • 1
  • 19
  • 28
Bellots
  • 1,703
  • 3
  • 19
  • 29
  • 2
    For those who want to do the same with Homestead, [check out my answer for that](http://stackoverflow.com/a/43144708/1494454). – totymedli Mar 31 '17 at 15:50

6 Answers6

149

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
Bogdan
  • 43,166
  • 12
  • 128
  • 129
  • ```Failed to listen on 0.0.0.0:80``` – JCarlosR Feb 05 '17 at 14:49
  • 4
    @JCarlos that's probably because you have another service running on port `80` (perhaps Apache, nginx or some other http server). Try using another port such as `8000` or stop the service running on port `80`. – Bogdan Feb 07 '17 at 09:51
  • I'm getting errors like ```SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.``` – 4ndro1d Mar 03 '17 at 15:54
  • Check your ip address using -> ipconfig (eg. 192.168.120.15) -> then browse through that 192.168.120.15:8000 – Aman May 19 '20 at 22:57
12

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.

Sand Of Vega
  • 2,297
  • 16
  • 29
Ragabazh
  • 131
  • 1
  • 5
5

There are so many ways to do this.

  1. Access your web via IP address from your iPhone, e.g. http://192.168.1.100/laravel
  2. 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
  3. Upload laravel app to web server and config it a test domain, e.g. dev.domain.com, or dev.domain.com:8080
  4. If you can config your WiFi router, you can give your computer a "port forwarding" or set "DMZ"
  5. 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
    
Elf Sundae
  • 1,575
  • 16
  • 23
  • Can you provide me a more detailed answer for the first solution? Thank you! – Bellots Jun 05 '15 at 20:29
  • 1
    @Bellots If your iPhone and your computer are in the same network, then you can access your local web server from iPhone via your computer's IP address. For example, your website could be opened with `http://127.0.0.1/laravel` on your computer, then if your computer's IP is `192.168.1.100`, then you can open website via `http://192.168.1.100/laravel` on your iPhone. – Elf Sundae Jun 05 '15 at 20:42
  • I googled a tutorial: https://www.devside.net/wamp-server/accessing-websites-on-a-local-network-lan-web-server – Elf Sundae Jun 05 '15 at 20:44
0

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

Alex Kyriakidis
  • 2,861
  • 1
  • 19
  • 28
  • This is not a problem, you can just copy paste your project inside vagrant directory and you are done. – Alex Kyriakidis Jun 05 '15 at 20:33
  • Sorry for my question, but isn't there a way to access to my app without Homestead? Like any other website, configuring a simple virtual host? – Bellots Jun 05 '15 at 20:35
  • If you want to manually setup a virtual host, have a look at this http://stackoverflow.com/questions/9682262/how-do-i-connect-to-this-localhost-from-another-computer-on-the-same-network – Alex Kyriakidis Jun 05 '15 at 20:39
0

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.

Mister Verleg
  • 4,053
  • 5
  • 43
  • 68
0

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