MacOSをホスト、CentOS6.5をゲストにしたVagrant環境を使って、FuelPHPの開発環境(オールインワン)を構築する手順。
ソースの修正とブラウザでのテストはホスト側、oilコマンドの実行はゲスト側で行う。
設定
以下の様に設定するものとする。
項目 | 設定値 |
---|---|
Vagrantディレクトリ | /path/to/vagrant/ |
ローカルマシンからプロジェクトへのアクセスURL | http://localhost:8080/PROJECT/ |
プロジェクトファイルのpath(ローカル側) | /path/to/vagrant/PROJECT/ |
プロジェクトファイルのpath(ゲスト側) | /vagrant/PROJECT/ |
Vagrant共有フォルダの所有ユーザー | vagrant ( グループは vagrant ) |
httpd のDocumentRoot | /var/www/html |
phpのセッションディレクトリ | /var/lib/php/session |
ローカルマシン -> 仮想マシンの80番ポートフォワードの設定
/path/to/vagrant/Vagrantfile の以下の記述をコメントアウト
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 80, host: 8080
FuelPHPに必要なパッケージのインストール
CentOS上で以下を実行
# yum install php
# yum install git
# yum install php-pdo
# yum install php-mysql
# yum install mysql-server
# yum install php-dom
# yum install php-mbstring
#コピペ用
# yum install php git php-pdo php-mysql mysql-server php-dom php-mbistring
PHPのTimezoneを設定
仮想マシンの /etc/php.ini の Timezone を設定
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = 'Asia/Tokyo'
.htaccess による overwrite を許可する
仮想マシンの /etc/httpd/conf/httpd.conf で、<Directory />
の AllowOverwrite を許可する
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
httpd実行ユーザーの変更
/etc/httpd/conf/httpd.conf で、Userをvagrantに、Groupをvagrantに変更する
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# . On SCO (ODT 3) use "User nouser" and "Group nogroup".
# . On HPUX you may not be able to use shared memory as nobody, and the
# suggested workaround is to create a user www and use that user.
# NOTE that some kernels refuse to setgid(Group) or semctl(IPC_SET)
# when the value of (unsigned)Group is above 60000;
# don't use Group #-1 on these systems!
#
User vagrant
Group vagrant
httpdのキャッシュ機能をオフ
共有フォルダのファイルをキャッシュさせないように、/etc/httpd/conf/httpd.confの `<Directory />
ディレクティブに EnableMMAP とEnableSendfile を記述
<Directory />
Options FollowSymLinks
AllowOverride None
EnableMMAP Off
EnableSendfile Off
</Directory>
fuelPHPがsessionディレクトリに書き込みできるようにする
仮想マシン上で、rootユーザーで以下を実行
# chown root.vagrant /var/lib/php/session
FuelPHP(oilコマンド)のインストール
仮想マシン上で、rootユーザーで以下を実行
# curl get.fuelphp.com/oil | sh
FuelPHPプロジェクトを作成
仮想マシンの vagrantユーザーで以下を実行
$ cd /vagrant
$ oil create PROJECT
httpdでFuelPHPプロジェクトを公開する
仮想マシンの rootユーザーで、Projectファイルへのシンボリックリンクを貼る
# ln -s /vagrant/PROJECT/public /var/www/html/PROJECT
MySQLのデータベースとユーザーを追加する
-> http://qiita.com/gigatune/items/cb9f9a53ea8454dbf220
その他
システムの設定
- iptablesの80版ポートを開放
- httpdサービスを常時起動するように設定
- mysqldサービスを常時起動するように設定
FuelPHPの設定
- fuel/app/config/config.php で、ormパッケージの自動ロード
- fuel/app/config/ 以下に database の設定