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

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

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

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

VirtualBox

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

Vagrant

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

Q&A

解決済

1回答

1880閲覧

vagrant使用でブラウザにうまく繋がってくれない

kkkkkkimkkk

総合スコア12

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

VirtualBox

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

Vagrant

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

0グッド

2クリップ

投稿2018/08/18 04:47

編集2018/08/19 04:38

phpの勉強中です。

「確かな力が身につく PHP「超」入門」という参考書を使用しています。

後半のチャプターで制作物を公開するパートまで行ったのですが
vagrant upがうまくできず ブラウザ「google chrome」にうまく繋がってくれません。
何をどうしたらいいのかお教え頂きたいです。
vagrant upした後にパスを入力した結果になります。

vagrant up後のターミナル結果です。
vagrant up後のターミナル結果です。

vagrant statusです。
vagrant statusです。

該当のソースコード

vagrant up

試したこと

VirtualBoxとVagrantをアンインストールして再度インストールしても変化なしです。

補足情報(FW/ツールのバージョンなど)

VirtualBoxとVagrantはどちらもバージョンは最新です。

vagrantFileは参考書のコードをそのまま使用していました。
vagrantFile

bootstrap.shも同様です。
bootstrap.sh

###追記 実施後
回答ありがとうございます。
vagrant up
vagrant ssh

$ sudo apt update -y
$ sudo apt install -y apache2
$ sudo apachectl status を実施しました。

下記が実行結果です。
ターミナル
vagrant@vagrant-ubuntu-trusty-64:~$ sudo apachectl status
Apache Server Status for localhost (via 127.0.0.1)

Server Version: Apache/2.4.7 (Ubuntu)
Server MPM: event
Server Built: Apr 18 2018 15:36:26


Current Time: Saturday, 18-Aug-2018 14:58:42 UTC
Restart Time: Saturday, 18-Aug-2018 14:58:23 UTC
Parent Server Config. Generation: 1
Parent Server MPM Generation: 0
Server uptime: 19 seconds
Server load: 0.15 0.07 0.06
Total accesses: 0 - Total Traffic: 0 kB
CPU Usage: u0 s0 cu0 cs0
0 requests/sec - 0 B/second -
1 requests currently being processed, 49 idle workers

PID Connections Threads Async connections
total accepting busy idle writing keep-alive closing
10369 0 yes 0 25 0 0 0
10370 0 yes 1 24 0 0 0
Sum 0 1 49 0 0 0

___________W..............
................................................................
......................

Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process
vagrant@vagrant-ubuntu-trusty-64:~$

以上です。
already runningが出ているかは不明ですが

Apace2 Ubuntu Default Pageへはアクセスできました。
イメージ説明

ここから下の階層へアクセスするにはどうすればいいんでしょうか?

現在
ホーム→vagrantフォルダ→htmlフォルダ(vagrantFile,bootstrap.sh同階層)→phpフォルダ→chapter2フォルダ→phpファイル
という構造になっています。

参考書では
http://localhost:8080/php/chapter2/welcome.php
とブラウザで開くとphpファイルが開くようなのですがApace2 Ubuntu Default Pageのページからurlを追加してみてもNot Foundでした。

これはファイルの保存先が間違えているのでしょうか?

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

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

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

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

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

guest

回答1

0

ベストアンサー

apacheは起動できているか?
apacheのdocument root設定は適切か?を確認する必要があります。

追記

私の手元で試しました。

Vagrantfile

# -*- mode: ruby -*- # vi: set ft=ruby : # All Vagrant configuration is done below. The "2" in Vagrant.configure # configures the configuration version (we support older styles for # backwards compatibility). Please don't change it unless you know what # you're doing. Vagrant.configure("2") do |config| config.vm.box = "ubuntu/trusty64" config.vm.network "forwarded_port", guest: 80, host: 8080 end
vagrant up vagrant ssh

仮想マシンの中に入ったら、以下を順に実行。

$ sudo apt update -y $ sudo apt install -y apache2 $ sudo apachectl status AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.2.15. Set the 'ServerName' directive globally to suppress this message httpd (pid 2831) already running # ←already runningが出ているかを確認しましょう

localhost:8080 をブラウザで見る→ Apace2 Ubuntu Default Page が表示される
まずはここまで確認して下さい。

追記2

私の仮想環境でもPHPを入れました。

$ sudo apt install -y php5 # とりあえずphp5を入れました

apacheの設定ファイルは /etc/apache2 配下にあります。
今回チェックしないといけないのは /etc/apache2/sites-enabled/000-default.conf です。
見てみましょう。

$ cat /etc/apache2/sites-enabled/000-default.conf <VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost>

ワーッと出てきてよく分からないと思いますが、見るべきは DocumentRoot という項目です。

DocumentRoot /var/www/html

/var/www/html とあります。

ここにファイルを置くとサーバが見てくれます。
すでにここには index.html があります。
先程の Apace2 Ubuntu Default Page を表示するhtmlファイルですね。

$ ls /var/www/html/index.html index.html # ←Apace2 Ubuntu Default Page用のファイル

実際に動作確認してみます。
/var/www/html 下に phptest というフォルダを作ります。
この下にテストファイルを置きます。

$ sudo mkdir /var/www/html/phptest

で、テスト用のPHPファイルを作りますが、その前に html フォルダ以下の権限を緩めておきます。
これは危険な設定なので外部に公開する本番サーバではNGです。

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

phpinfo.php ファイルを作成します。

$ echo "<?php phpinfo();" > /var/www/html/phptest/phpinfo.php

これでファイルが作成できました。
では、ブラウザから localhost:8080/phptest/phpinfo.php を見て下さい。
PHP INFO ページが確認できれば、後は自力でできそうではないですか?
如何でしょうか?

追記3

自分で作成したファイルをphptestフォルダに入れたいのですがこれはどこにあるのでしょうか?

Macと仮想マシン間で ストレージの同期 を行う必要があります。

Vagrantfileconfig.vm.synced_folder を追記します。

Vagrant.configure("2") do |config| config.vm.box = "ubuntu/trusty64" config.vm.network "forwarded_port", guest: 80, host: 8080 config.vm.synced_folder "./", "/var/www/html" # ←追記 end

仮想マシンを再起動して設定を反映。

vagrant reload --provision

すると Vagrantfile が置かれているフォルダが仮想マシンの /var/www/html とシンクロするはずです。

http://laraweb.net/environment/84/

投稿2018/08/18 05:01

編集2018/08/19 02:05
退会済みユーザー

退会済みユーザー

総合スコア0

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

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

kkkkkkimkkk

2018/08/18 11:15

回答ありがとうございます。 $ locate httpd.conf をターミナルで実行したところ WARNING: The locate database (/var/db/locate.database) does not exist. To create the database, run the following command: sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist Please be aware that the database can take some time to generate; once the database has been created, this message will no longer appear. 上記が出ました。 その次に$ sudo launchctl loadsudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist  を実行したのですが次に下記が表示されました Unrecognized subcommand: loadsudo Usage: launchctl <subcommand> ... | help [subcommand] Many subcommands take a target specifier that refers to a domain or service within that domain. The available specifier forms are: system/[service-name] Targets the system-wide domain or service within. Root privileges are required to make modifications. user/<uid>/[service-name] Targets the user domain or service within. A process running as the target user may make modifications. Root may modify any user's domain. User domains do not exist on iOS. gui/<uid>/[service-name] Targets the GUI domain or service within. Each GUI domain is associated with a user domain, and a process running as the owner of that user domain may make modifications. Root may modify any GUI domain. GUI domains do not exist on iOS. session/<asid>/[service-name] Targets a session domain or service within. A process running within the target security audit session may make modifications. Root may modify any session domain. pid/<pid>/[service-name] Targets a process domain or service within. Only the process which owns the domain may modify it. Even root may not do so. When using a legacy subcommand which manipulates a domain, the target domain is inferred from the current execution context. When run as root (whether it is via a root shell or sudo(1)), the target domain is assumed to be the system-wide domain. When run from a normal user's shell, the target is assumed to be the per-user domain for that current user. Subcommands: bootstrap Bootstraps a domain or a service into a domain. bootout Tears down a domain or removes a service from a domain. enable Enables an existing service. disable Disables an existing service. uncache Removes the specified service name from the service cache. kickstart Forces an existing service to start. attach Attach the system's debugger to a service. debug Configures the next invocation of a service for debugging. kill Sends a signal to the service instance. blame Prints the reason a service is running. print Prints a description of a domain or service. print-cache Prints information about the service cache. print-disabled Prints which services are disabled. plist Prints a property list embedded in a binary (targets the Info.plist by default). procinfo Prints port information about a process. hostinfo Prints port information about the host. resolveport Resolves a port name from a process to an endpoint in launchd. limit Reads or modifies launchd's resource limits. runstats Prints performance statistics for a service. examine Runs the specified analysis tool against launchd in a non-reentrant manner. config Modifies persistent configuration parameters for launchd domains. dumpstate Dumps launchd state to stdout. dumpjpcategory Dumps the jetsam properties category for all services. reboot Initiates a system reboot of the specified type. bootshell Brings the system up from single-user mode with a console shell. load Bootstraps a service or directory of services. unload Unloads a service or directory of services. remove Unloads the specified service name. list Lists information about services. start Starts the specified service. stop Stops the specified service if it is running. setenv Sets the specified environment variables for all services within the domain. unsetenv Unsets the specified environment variables for all services within the domain. getenv Gets the value of an environment variable from within launchd. bsexec Execute a program in another process' bootstrap context. asuser Execute a program in the bootstrap context of a given user. submit Submit a basic job from the command line. managerpid Prints the PID of the launchd controlling the session. manageruid Prints the UID of the current launchd session. managername Prints the name of the current launchd session. error Prints a description of an error. variant Prints the launchd variant. version Prints the launchd version. help Prints the usage for a given subcommand. 以上です。 ちなみにへブラウザの変化はありません。 すみません、環境構築をしたことがなく、独学で勉強しており詰まっております。 何卒、ご教授願います。
退会済みユーザー

退会済みユーザー

2018/08/18 11:57

なるほどですね。 今、私の手元で動かしてみているのでお待ち下さい。
退会済みユーザー

退会済みユーザー

2018/08/18 12:39

追記したので確認してみて下さい。
kkkkkkimkkk

2018/08/18 15:21

回答ありがとうございました。 非常に助かります。 実行結果記載しましたので ご教授頂けましたらお願いします。
退会済みユーザー

退会済みユーザー

2018/08/18 15:23

いい感じですね。 apacheは起動できています。 あとはファイルの置き場所ですね。 ちょっとお待ち下さい。
退会済みユーザー

退会済みユーザー

2018/08/18 16:04

また追記しました。
kkkkkkimkkk

2018/08/19 00:52

本当にありがとうございます。phpinfo.php表示できました。 自分で作成したファイルをphptestフォルダに入れたいのですがこれはどこにあるのでしょうか? 私はmacを使っていて、Finderのどこかにあるのかな?というイメージでしたが phptestフォルダの場所が特定できず、お恥ずかしながらここまでご教授頂いたのにまだ解決できません。
退会済みユーザー

退会済みユーザー

2018/08/19 02:05

追記しました。
kkkkkkimkkk

2018/08/19 04:41

解決できました!! たくさんアドバイス頂き、本当にありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問