LoginSignup
1
1

More than 5 years have passed since last update.

homestead up で The forwarded port to 8000 is already in use on the host machine. と言われる解決方法

Last updated at Posted at 2015-01-10

Mac+vagrant環境で、vagrantが立ち上がらず、homestead upがうまくいきませんでした(☝ ՞ਊ ՞)

前提条件

Macにbrewでcomposerをインストール済みで、homesteadをcomposerでインストール済みとします。

homesteadをインストール
composer global require laravel/homestead:v2.0.7

なぜv2.0.7なのはv2.0.8でエラーが出たからです。

homestead upでportが使われているとエラー

homestead upをしてvagrantを立ち上げます。

homestead up

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'laravel/homestead'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'laravel/homestead' is up to date...
==> default: Setting the name of the VM: homestead
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 8000 is already in use
on the host machine.

To fix this, modify your current projects Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:

  config.vm.network :forwarded_port, guest: 80, host: 1234

Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding.

portを変えろとあります。

homestead.rbに書いてあるhostの番号を変更する

Macの~/.composerディレクトリの下にhomesteadディレクトリがありますので、そちらのhomestead.rbを変更しました。

homestead.rbのhost番号を変更する
vi ~/.composer/vendor/laravel/homestead/scripts/homestead.rb

# 元からあった8000番の記述をコメントに
# config.vm.network "forwarded_port", guest: 80, host: 8000
# 8080番を追加
config.vm.network "forwarded_port", guest: 80, host: 8080

homestead.rbにhost8000番の記述があったので、8080(適当)番に変更しました。

homesteadのディレクトリにVagrantfileがあり、こっちの ~/.composer/vendor/laravel/homestead/Vagrantfile にforwarded_portを書いたらいいのかな?と思ったのですが、Vagrantfileに書いてもダメでした\(^o^)/

再度homestead up

再度homestead upを試します。

homesteadをup
homestead up

今度は起動できました。

もっとスマートな方法はないのかしら(☝ ՞ਊ ՞)

1
1
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
1
1