質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

Debian

Debianは、Debian GNU/Linux などのOS(オペレーティングシステム)です。

Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

Q&A

2回答

2399閲覧

Debian(Vagarnt)におけるCakePHPの環境構築について(開発サーバにアクセス出来ない)

marimo.

総合スコア48

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

Debian

Debianは、Debian GNU/Linux などのOS(オペレーティングシステム)です。

Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

0グッド

1クリップ

投稿2016/09/04 08:30

DebianのVagrantを立ち上げてそこでCakePHPの環境を構築しようと試みている者です.
Cakeにはbin/cake serverという開発環境サーバを立ち上げるコマンドがあると思います.
GuestのVagrantでそのコマンドを実行すると以下の様なプログラムが走りました.

shell

1vagrant@debian-jessie:/vagrant/app$ bin/cake server 2 3Welcome to CakePHP v3.3.0 Console 4--------------------------------------------------------------- 5App : src 6Path: /vagrant/app/src/ 7DocumentRoot: /vagrant/rakubo/webroot 8--------------------------------------------------------------- 9built-in server is running in http://localhost:8765/ 10You can exit with `CTRL-C`

ここでいうlocalhostはVagrant側のことなのでhostマシンのブラウザで確認するには少し工夫が必要だと思いました.以下がVagrantfileです.

Vagrantfile

1# -*- mode: ruby -*- 2# vi: set ft=ruby : 3 4# All Vagrant configuration is done below. The "2" in Vagrant.configure 5# configures the configuration version (we support older styles for 6# backwards compatibility). Please don't change it unless you know what 7# you're doing. 8Vagrant.configure(2) do |config| 9 # The most common configuration options are documented and commented below. 10 # For a complete reference, please see the online documentation at 11 # https://docs.vagrantup.com. 12 13 # Every Vagrant development environment requires a box. You can search for 14 # boxes at https://atlas.hashicorp.com/search. 15 config.vm.box = "debian/jessie64" 16 17 # Disable automatic box update checking. If you disable this, then 18 # boxes will only be checked for updates when the user runs 19 # `vagrant box outdated`. This is not recommended. 20 # config.vm.box_check_update = false 21 22 # Create a forwarded port mapping which allows access to a specific port 23 # within the machine from a port on the host machine. In the example below, 24 # accessing "localhost:8080" will access port 80 on the guest machine. 25 config.vm.network "forwarded_port", guest: 8765, host: 8080 26 27 # Create a private network, which allows host-only access to the machine 28 # using a specific IP. 29 config.vm.network "private_network", ip: "192.168.33.10" 30 31 # Create a public network, which generally matched to bridged network. 32 # Bridged networks make the machine appear as another physical device on 33 # your network. 34 # config.vm.network "public_network" 35 36 # Share an additional folder to the guest VM. The first argument is 37 # the path on the host to the actual folder. The second argument is 38 # the path on the guest to mount the folder. And the optional third 39 # argument is a set of non-required options. 40 config.vm.synced_folder "./", "/vagrant", type: "virtualbox" 41 42 # Provider-specific configuration so you can fine-tune various 43 # backing providers for Vagrant. These expose provider-specific options. 44 # Example for VirtualBox: 45 # 46 # config.vm.provider "virtualbox" do |vb| 47 # # Display the VirtualBox GUI when booting the machine 48 # vb.gui = true 49 # 50 # # Customize the amount of memory on the VM: 51 # vb.memory = "1024" 52 # end 53 # 54 # View the documentation for the provider you are using for more 55 # information on available options. 56 57 # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies 58 # such as FTP and Heroku are also available. See the documentation at 59 # https://docs.vagrantup.com/v2/push/atlas.html for more information. 60 # config.push.define "atlas" do |push| 61 # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" 62 # end 63 64 # Enable provisioning with a shell script. Additional provisioners such as 65 # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the 66 # documentation for more information about their specific syntax and use. 67 # config.vm.provision "shell", inline: <<-SHELL 68 # sudo apt-get update 69 # sudo apt-get install -y apache2 70 # SHELL 71end

ここで問題が発生しました.
Guestの8765portとHostの8080portをポートフォワーディングしたのにもかかわらず,http://localhost:8080にアクセスが出来ないのです.
ちなみに,

  • Hostからping 192.168.33.10は通ります
  • Hostからping 192.168.33.10:8765ping: cannot resolve 192.168.33.10:8765: Unknown host
  • Hostからping localhost:8080ping: cannot resolve 192.168.33.10:8765: Unknown host

vagrant reloadを見る限りポートフォワーディングはできているようなのですが…

$ vagrant reload ==> default: Attempting graceful shutdown of VM... ==> default: Checking if box 'debian/jessie64' is up to date... ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> default: Forwarding ports... default: 8765 (guest) => 8080 (host) (adapter 1) default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key ==> default: Machine booted and ready! [default] GuestAdditions 5.0.10 running --- OK. ==> default: Checking for guest additions in VM... ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => /Users/hoge/Vagrant/debian-jessie64 ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: flag to force provisioning. Provisioners marked to run always will still run.

どうやったらCakePHPの開発サーバをホストから確認ができるようになるのか,お知恵を貸していただけませんでしょうか?
よろしくお願いいたします.

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

[メモ]cakephp3のbin/cake serverでvagrantで接続できない問題解決
http://qiita.com/waterada/items/ffd41970bbaf57e19d76

上記のURLに記載してあるように、以下のようにすれば、接続できるようになると思います。

bin/cake server -H 0.0.0.0 -p 8765

投稿2017/06/16 13:43

wate

総合スコア10

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

その設定で以下の様に起動した場合はどうですか?

bin/cake server -H 192.168.33.10 -p 8765

また、debian側のfirewallや、SELinuxの設定にも気を付けてください。

投稿2016/09/04 10:21

flied_onion

総合スコア2604

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

marimo.

2016/09/04 11:12

ufwコマンド(ufw allow 8765)を使って8765ポートを開放してみましたが結果は変わりませんでした.(pingが通らない) bin/cake server -H 192.168.33.10 -p 8765も同様です. SELinuxについては初めて聞いたので今調べている最中です. 取り急ぎ報告まで.
pack

2016/09/14 11:30

私の環境(Ubuntu)では、こちらの方の回答にあるように、 ``` bin/cake server -H 192.168.33.100 Welcome to CakePHP v3.3.3 Console --------------------------------------------------------------- App : src Path: /home/vagrant/myapp/src/ DocumentRoot: /home/vagrant/myapp/webroot --------------------------------------------------------------- built-in server is running in http://192.168.33.100:8765/ You can exit with `CTRL-C` ``` ブラウザから、http://192.168.33.100:8765 でアクセスできます。 ポートフォワーディングは、しておりません。 あと、pingでポートが開いているかどうかは確認できませんので。 ping: cannot resolve 192.168.33.10:8765: Unknown host は当然の結果です。 例えば、Windowsですと、Host(Windows)側からコマンドで > telnet 192.168.33.100 8888 接続中: 192.168.33.100...ホストへ接続できませんでした。 ポート番号 8888: 接続に失敗しました となるか、 > telnet 192.168.33.100 8765 → 画面真っ黒 → 止めると、cake server の方がログを返す。 [Wed Sep 14 11:25:14 2016] 192.168.33.1:52766 Invalid request (Malformed HTTP request) (つまりは開いている) というような確認の仕方があります。
pack

2016/09/14 12:39

pingでポート確認ですが、 ping localhost:8080はping: cannot resolve 192.168.33.10:8765: Unknown host を見ると、ポート指定出来ているようにも見えますが、何かそういうのがあるのですかね? すみません。話が逸れてしまって。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問