LoginSignup
14
13

More than 5 years have passed since last update.

Mac OSX Mavericks(10.9)にFuelPHPを導入する方法 と Web共有設定をターミナルからする方法 と ドキュメントルートの変更

Posted at

目標確認

http://localhost にアクセスして以下の画面が表示されることが目標。
fuelPHP.png

通常MacではWeb共有をすれば、http://localhost/~{username} で /Users/{Username}/Sites/public_html 以下のデータが読めるようになります。

しかし今回はDocumentRootを別の作業用ディレクトリに設定します。

Apacheの設定

まずデフォルトで入っている(はずの)Apacheのバージョンを確認します。

hoge% http -v
Server version: Apache/2.2.24 (Unix)
Server built:   Aug 24 2013 21:10:43

やんなくても問題無いですが、マシン起動時にApacheも立ち上がる様に設定します。

hoge% sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
Password:

Apacheの変更を反映させる為にリスタートします。でも多分、gracefulの方がいいかもしれないけど、はっきりは分かりません。

hoge% sudo apachectl configtest
Syntax OK
hoge% sudo apachectl graceful
(△ sudo apachectl restart)

Apacheの設定をいじります。

各アカウントのconfファイルがない場合は作成します。

hoge% sudo vim /etc/apache2/users/{username}.conf
----
<Directory "/Users/{username}/Sites"> #DocumentRootの指定をします。通常だとこちらです。
#<Directory "/Users/{username}/workspace/fuga"> #DocumentRootは変更できます。
    AllowOverride All
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec ExecCGI
    AddHandler cgi-script .cgi
    <Limit GET POST OPTIONS PROPFIND>
        Order allow,deny
        Allow from all
    </Limit>
    <LimitExcept GET POST OPTIONS PROPFIND>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>

# ここも設定します
#AllowOverride None
AllowOverride All 
----

バーチャルホストの設定

バーチャルホストを設定します。しなくてもいいですが、私は複数ホストを利用したかったので、しました。
なお、httpd.confをいじるときはバックアップをとりましょう。

hoge% sudo cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.yymmdd
hoge% sudo vim /etc/apache2/httpd.conf
# Virtual hosts
-#Include /private/etc/apache2/extra/httpd-vhosts.conf
+Include /private/etc/apache2/extra/httpd-vhosts.conf

#.htaccessの有効化
#AllowOverride None
AllowOverride All

次にバーチャルホストの中身を設定します。
この時、デフォルトの設定はコメントアウトします。

hoge% sudo vim /etc/apache2/extra/httpd-vhosts.conf
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot "/usr/docs/dummy-host.example.com"
#    ServerName dummy-host.example.com
#    ServerAlias www.dummy-host.example.com
#    ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
#    CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" comm
#</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    ServerName localhost
    #ServerAlias www.dummy-host.example.com
    ErrorLog "/private/var/log/apache2/error.log"
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    CustomLog "/private/var/log/apache2/access.log" combined

    # DocumentRoot "/Users/{username}/workspace/fuga/public/" #ここでDocumentRootを変更できます
    DocumentRoot "/Users/{username}/Sites" #通常の設定にしたい場合はこちら。 /Users/{username}/Sites/public_html の方が一般的かも。
    <Directory "/">
        AllowOverride All
        Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec ExecCGI
        AddHandler cgi-script .cgi
        <Limit GET POST OPTIONS PROPFIND>
            Order allow,deny
            Allow from all
        </Limit>
        <LimitExcept GET POST OPTIONS PROPFIND>
            Order deny,allow
            Deny from all
        </LimitExcept>
    </Directory>
</VirtualHost>

変更を反映させます。

hoge% sudo apachectl configtest                                              [/etc/apache2/users]
Warning: DocumentRoot [/Users/hoge/Sites/] does not exist
httpd: apr_sockaddr_info_get() failed for hoge-no-macbookAir
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK

私の場合はSitesディレクトリがなかったので作りました。
適当な文字列のindex.htmlファイルを作成し、Apacheを更新します。

hoge% mkdir -p ~/Sites
hoge% echo Now Web Sharing! > ~/Sites/index.html  
hoge% sudo apachectl restart    

一旦ここで、 http://localhost/~{username} にアクセスすると、Now Web Sharing! と表示されたページが出てくるかと思います。
スクリーンショット 2014-01-21 3.21.11 pm.png

ドキュメントルートの変更

ドキュメントルートを変更するには以下の3ファイルをいじります。

$sudo vi /etc/apache2/httpd.conf
---
# 2箇所あります

#DocumentRoot "/Library/WebServer/Documents"
 DocumentRoot "Users/{username}/workspace/fuga"

#<Directory "/Library/WebServer/Documents">
 <Directory "Users/{username}/workspace/fuga">

次にバーチャルホストと各ユーザーのconfです。

hoge% sudo vim /etc/apache2/extra/httpd-vhosts.conf
hoge% sudo vim /etc/apache2/users/{username}.conf

#両ファイルとも以下の Users/{username}/workspace/fuga 部分を指定したいパスに変更します
----
<Directory "/Users/{username}/workspace/fuga">
    Options ・・・・
    Allow ・・・・
     
     
</Directory>
----

するとこの場所においたindex.htmlが http://localhost で見れるようになります。

PHPの設定

hoge% php -v                                                                 [/etc/apache2/users
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

mod_rewire モジュールがあることを確認

$httpd -M

httpd.confでphp5_moduleを読み込ませます。

hoge% sudo vim /etc/apache2/httpd.conf 
-#LoadModule php5_module libexec/apache2/libphp5.so
+LoadModule php5_module libexec/apache2/libphp5.so

php.ini.defaultをphp.iniにコピーし、編集します。

hoge% sudo cp /etc/php.ini.default /etc/php.ini
hoge% sudo chmod 644 /etc/php.ini 
hoge% sudo vim /etc/php.ini
; http://php.net/date.timezone
→date.timezone ="Asia/Tokyo"

phpが有効になったことを確認します。

$ vim ~workspace/fuga/test.php
---
<?php
phpinfo();
?>
---

http://localhost/test.php にアクセス。

PHPのバージョン情報などが表示されればOK。
スクリーンショット 2014-01-21 3.26.33 pm.png

FuelPHPのインストール

$ curl get.fuelphp.com/oil | sh

FuelPHPでプロジェクト作成

自分の作業用ディレクトリで。

$ cd ~/workspace/fuga/nemu
$ oil create blog
---

FuelPHPの目標の画面を http://localhost/ で出すには、DocumentRootを、oil create した作業用ディレクトリの下のpublicディレクトリに設定します。

これで見れるようになります。

http://localhost/ 
![fuelPHP.png](https://qiita-image-store.s3.amazonaws.com/0/18705/e18aef2b-b1d1-c573-7804-9f35667ba03a.png)


また、 http://localhost/~{username} は、変わらず見れます。
14
13
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
14
13