LoginSignup
0
2

More than 3 years have passed since last update.

【Laravel】Homestead上のサイトにスマホからアクセスする

Last updated at Posted at 2020-02-25

環境

  • Vagrant 2.2.7
  • Laravel Homestead 9.2.0

事前準備

開発用マシン(Laravel Homesteadを実行しているマシン)とスマホを同じWi-Fi(LAN)に接続してから設定作業に進んでください。

設定

プロビジョニングスクリプト修正

スマホからアクセスできるように、仮想マシンにパブリックな(他のホストから見える)IPを振ってあげます。
config.vm.network :public_network, ip: '192.168.0.100'を追記します。
IPアドレスは空いてるものなら何でもいいですが、LAN内のサブネットを指定しないと繋がらないため、注意してください。(私の環境では、192.168.1.100だと接続できませんでした。)

~/Homestead/scripts/homestead.rb(更新前)

# 略

# Configure A Private Network IP
if settings['ip'] != 'autonetwork'
  config.vm.network :private_network, ip: settings['ip'] ||= '192.168.10.10'
else
  config.vm.network :private_network, ip: '0.0.0.0', auto_network: true
end

# Configure Additional Networks

# 略

~/Homestead/scripts/homestead.rb(更新後)

# 略

# Configure A Private Network IP
if settings['ip'] != 'autonetwork'
  config.vm.network :private_network, ip: settings['ip'] ||= '192.168.10.10'
else
  config.vm.network :private_network, ip: '0.0.0.0', auto_network: true
end

config.vm.network :public_network, ip: '192.168.0.100' # ←追記

# Configure Additional Networks

# 略

仮想マシンの再プロビジョニング

以下のコマンドを叩いて、仮想マシンを作り直します。
インタフェースにWi-Fiを指定して、プロビジョニングの完了を待ちます。


$ vagrant reload --provision
==> homestead: Attempting graceful shutdown of VM...
==> homestead: Checking if box 'laravel/homestead' version '9.2.0' is up to date...
==> homestead: Clearing any previously set forwarded ports...
==> homestead: Clearing any previously set network interfaces...
==> homestead: Available bridged network interfaces:
1) en0: Wi-Fi (AirPort)
2) p2p0
3) awdl0
4) en1: Thunderbolt 1
5) en2: Thunderbolt 2
6) bridge0
==> homestead: When choosing an interface, it is usually the one that is
==> homestead: being used to connect to the internet.
==> homestead:
    homestead: Which interface should the network bridge to? 1

アクセスしてみる

スマホで http://192.168.0.100/ にアクセスするとサイトが見えるようになっているはずです。
やったね!

参考

macos - vagrant homestead - public network not working on osx - Stack Overflow
https://stackoverflow.com/questions/26353186/vagrant-homestead-public-network-not-working-on-osx

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2