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

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

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

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

VirtualBox

VirtualBoxは、現在米オラクル社が開発している、 x86仮想化ソフトウェア・パッケージの一つです。

Vagrant

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

Q&A

解決済

1回答

1135閲覧

CakePHP2でリンクにアクセスしても画面が表示されません。

YusukeAnzai

総合スコア13

CakePHP

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

VirtualBox

VirtualBoxは、現在米オラクル社が開発している、 x86仮想化ソフトウェア・パッケージの一つです。

Vagrant

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

0グッド

1クリップ

投稿2018/05/03 03:23

前提・実現したいこと

CakePHP2の入門を行なっています。
vagrantでの環境構築→サンプルコードを用いての画面表示を行なっています。

画面表示を行なっている際に、以下のエラーメッセージが発生しました。

このサイトにアクセスできません
localhost で接続が拒否されました。

試したこと

下記の2つのサイトを参考にしました。
環境構築 https://qiita.com/keita_watari/items/54833f7ccb05fbc4a18f
画面表示 http://webcake.no003.info/event/cakephp2-8hours-seminar.html

具体的な手順は、

1.上記環境構築リンクでの手順を行う。

2.https://github.com/cakephp/cakephp/tagsからcake2.10.9をダウンロード、vagrantの下の階層に置く。cakeにrename
*参考  

[vagrant@localhost vagrant]$ ls
Vagrantfile cake

3.リンクにアクセス。
http://localhost:8888/cake/
http://localhost:8080/cake/
http://localhost/cake/
3つとも表示されず。

ちなみに、php,mysqlのダウンロードと、サーバーの起動は確認できています。

php -v
PHP 5.6.36 (cli) (built: Apr 25 2018 10:11:47)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
[vagrant@localhost cake]$ mysql --version
mysql Ver 14.14 Distrib 5.6.40, for Linux (x86_64) using EditLine wrapper
[vagrant@localhost cake]$ sudo service httpd status
httpd (pid 2238) is running...

こちらのエラーに関して教えていただけると嬉しいです。よろしくお願いします。

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

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

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

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

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

退会済みユーザー

退会済みユーザー

2018/05/03 04:39

仮想マシンにはホスト側のcakeディレクトリを注入できているでしょうか?
YusukeAnzai

2018/05/03 04:43 編集

ご回答ありがとうございます! [vagrant@localhost vagrant]$ ls       Vagrantfile cake /vagrantにはcakeディレクトリが存在しています。 ご質問に対する回答として、あっているかわかりませんが...
退会済みユーザー

退会済みユーザー

2018/05/03 04:51

ありがとうございます。Apache httpd設定ファイルのDocumentRootはvagrant/cake/publicを向いていますでしょうか?(質問の意味がわからない場合はその旨教えて頂ければと思います)
YusukeAnzai

2018/05/03 05:05 編集

ありがとうございます! Apache httpd設定ファイルとは、httpd.confであっていますか?         参照 https://qiita.com/s2maeda/items/21d9458e44f86597d1ae DocumentRootはvagrant/cake/publicを向いていますでしょうか? -すいません、ここは何を指しているかわからないです。調べ中ですが。。。                                             httpd.conf # # This is the main Apache server configuration file. It contains the # configuration directives that give the server its instructions. # See <URL:http://httpd.apache.org/docs/2.2/> for detailed information. # In particular, see # <URL:http://httpd.apache.org/docs/2.2/mod/directives.html> # for a discussion of each configuration directive. # # # Do NOT simply read the instructions in here without understanding # what they do. They're here only as hints or reminders. If you are unsure # consult the online docs. You have been warned. # # The configuration directives are grouped into three basic sections: # 1. Directives that control the operation of the Apache server process as a # whole (the 'global environment'). # 2. Directives that define the parameters of the 'main' or 'default' server, # which responds to requests that aren't handled by a virtual host. # These directives also provide default values for the settings # of all virtual hosts. # 3. Settings for virtual hosts, which allow Web requests to be sent to # different IP addresses or hostnames and have them handled by the # same Apache server process. # # Configuration and logfile names: If the filenames you specify for many # of the server's control files begin with "/" (or "drive:/" for Win32), the # server will use that explicit path. If the filenames do *not* begin # with "/", the value of ServerRoot is prepended -- so "logs/foo.log" # with ServerRoot set to "/etc/httpd" will be interpreted by the # server as "/etc/httpd/logs/foo.log". # ### Section 1: Global Environment # # The directives in this section affect the overall operation of Apache, # such as the number of concurrent requests it can handle or where it # can find its configuration files. # # # Don't give away too much information about all the subcomponents # we are running. Comment out this line if you don't mind remote sites # finding out what major optional modules you are running ServerTokens OS # # ServerRoot: The top of the directory tree under which the server's # configuration, error, and log files are kept. # # NOTE! If you intend to place this on an NFS (or otherwise network) # mounted filesystem then please read the LockFile documentation
退会済みユーザー

退会済みユーザー

2018/05/03 05:18 編集

vi httpd.conf → /DocumentRoot で該当箇所検索できるでしょうか?viエディタ操作が難しい場合は全文コピー→ホスト側の好きなエディタにペースト→テキスト検索(Win→Ctrl+F Mac→Cmd+F)でも同じことができます。DocumentRoot部分の設定が知りたいです。
YusukeAnzai

2018/05/03 05:24 編集

ありがとうございます。 #<VirtualHost *:80> # ServerAdmin webmaster@dummy-host.example.com # DocumentRoot /www/docs/dummy-host.example.com # ServerName dummy-host.example.com # ErrorLog logs/dummy-host.example.com-error_log # CustomLog logs/dummy-host.example.com-access_log common #</VirtualHost> こちらになりました。
退会済みユーザー

退会済みユーザー

2018/05/03 05:28

ありがとうございます。お手数ですが、貼って頂いた部分の他にはなかったでしょうか?#でコメントアウトされていないDocumentRoot行があれば、その部分が欲しいです。
YusukeAnzai

2018/05/03 05:38

DocumentRoot "/var/www/html"
YusukeAnzai

2018/05/03 05:39 編集

すいません、現在検索中ですが、上記はコメントアウトされていませんでした。 コピペがうまくいかず、検索方法を調べています。
退会済みユーザー

退会済みユーザー

2018/05/03 05:42

ありがとうございます。その部分です。
guest

回答1

0

ベストアンサー

追記依頼で頂いた回答から、以下をお試し頂きたいと思います。
vagrant ssh直後、vagrantディレクトリ下にいる想定のコマンドです。

まず、cakeディレクトリを/var/www/html/下に移動させます。

bash

1sudo mv cake /var/www/html/

続いて、htmlディレクトリの権限設定を変更します。

bash

1sudo chown -R apache:apache /var/www/html

ブラウザで表示確認してみて下さい。

表示できていない場合、さらに以下を試します。

bash

1sudo chmod -R 777 /var/www/html

上手くいかなければその旨教えて下さい。

追記:
すみません、漏れがあったので追記します。

httpd.confのDocumentRootを以下のように修正して下さい。

DocumentRoot "/var/www/html/cake/app/webroot"

その後、apache httpdを再起動します。

bash

1sudo service httpd restart

追記2:

vagrantからexitして、ホスト側で以下操作してみて下さい。

Vagrantfileを編集します。

# config.vm.network :private_network, ip: "192.168.33.10"

上の行の#を削除してコメントアウトを解除して下さい。

その後、仮想マシンを再起動して設定反映します。

bash

1vagrant reload

ブラウザのアドレスバーに192.168.33.10または192.168.33.10/cakeと打ってアクセスしてみて下さい。

投稿2018/05/03 05:51

編集2018/05/03 07:25
退会済みユーザー

退会済みユーザー

総合スコア0

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

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

YusukeAnzai

2018/05/03 06:14

ありがとうございます! viで入った後に、 :wq(or :wq!) を実行すると、 "httpd.conf" E212: Can't open file for writing が起きるのですが、調べて見たところ権限がないという事かと思いました。 http://jsapachehtml.hatenablog.com/entry/2014/11/23/124350 ただ、:w !sudo tee % の"%"がわからないのですが、どうすれば権限をもらえますか? 何から何まですいません。
退会済みユーザー

退会済みユーザー

2018/05/03 06:21

いえ、私も最初何もわからなかったので、大丈夫ですよ。一旦 :q! で抜けてから sudo vi httpd.conf で編集をやり直してみて下さい。
退会済みユーザー

退会済みユーザー

2018/05/03 06:22

すごく雑な説明になりますが、コマンドの頭にsudoを付けるとrootという最強の権限で操作ができます。
退会済みユーザー

退会済みユーザー

2018/05/03 07:15

localhostじゃないと思いますね。ちょっと回答の方に追記するので、お待ち下さい。
退会済みユーザー

退会済みユーザー

2018/05/03 07:25

追記しました。ご確認下さい。
YusukeAnzai

2018/05/03 07:53 編集

ありがとうございます! http://192.168.33.10/にアクセスしたところ、 URL rewriting is not properly configured on your server. 1) Help me configure it 2) I don't / can't use URL rewriting と出ましたが、少し調べたところmod_rewriteというものが関係しているとのことでした。 上記メッセージが表示されたということは、あとはmod_rewriteを直せば出てきますかね。。 ちょっと自分で調べて見ます!!(調べてもわからなけばまた質問させていただけると嬉しいです。。。また、アクセスできた場合も報告させていただきます。) 本当に親切にありがとうございます!
退会済みユーザー

退会済みユーザー

2018/05/03 07:58

いえいえ、何かあればまた書き込み下さい。
YusukeAnzai

2018/05/07 13:06

アクセスできました! 本当にお世話になりました。ありがとうございました!
退会済みユーザー

退会済みユーザー

2018/05/07 13:12

よかったです。引き続き頑張って下さい。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問