PHPのフレームワークを使ってみた。あんまり好きじゃないけどお仕事ですからね〜 (>_<)
1.取りあえずrootで作っちゃう
⇒ 本当はアプリケーションアカウントを作って実施すべし。
$ sudo su -
2.プロジェクト用のディレクトリを作成
# cd /var/www/html/
# mkdir world
# cd world/
3.プロジェクト(スケルトン)作成
# symfony init-project world
Task "init-project" is not defined.
ってエラーが出たら、v1.4系なのにv1.0系のコマンドを使った証拠。やりなおし。
バージョン調べたければ事前に「$ symfony -V」してみる。
# symfony generate:project world
>> file+ /var/www/html/world/symfony
....
>> tokens /var/www/html/world/config/doctrine/schema.yml
>> tokens /var/www/html/world/lib/form/BaseForm.class.php
#
いろいろいる物を作ってくれる。
何も無かったところがこんな感じに。
# ls -l
drwxr-xr-x 2 root root 4096 May 23 11:26 apps
drwxrwxrwx 2 root root 4096 May 23 11:26 cache
drwxr-xr-x 3 root root 4096 May 23 11:26 config
drwxr-xr-x 3 root root 4096 May 23 11:26 data
drwxr-xr-x 3 root root 4096 May 23 11:26 lib
drwxrwxrwx 2 root root 4096 May 23 11:26 log
drwxr-xr-x 2 root root 4096 May 23 11:26 plugins
-rwxrwxrwx 1 root root 446 May 23 11:26 symfony
drwxr-xr-x 5 root root 4096 May 23 11:26 test
drwxr-xr-x 6 root root 4096 May 23 11:26 web
4.アプリケーション設置
# symfony generate:app traveler
>> dir+ /var/www/html/world/apps/traveler/modules
....
>> tokens /var/www/html/public_html/lib/form/BaseForm.class.php
#
なんかまた作ってくれる。
# ls -l ../world/apps/traveler/
drwxr-xr-x 2 root root 4096 May 23 16:41 config
drwxr-xr-x 2 root root 4096 May 23 16:41 i18n
drwxr-xr-x 2 root root 4096 May 23 16:41 lib
drwxr-xr-x 2 root root 4096 May 23 16:41 modules
drwxr-xr-x 2 root root 4096 May 23 16:41 templates
5.開発用ファイルを使えるようにする
# vi web/traveler_dev.php
この部分をコメントアウト
if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')))
{
die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
コメントアウトしないと開発環境のアプリケーションにアクセスした時に、
http://hogehoge.jp/hoge1_dev.php/
「You are not allowed to access this file. Check traveler_dev.php for more information.」
ってでて見えない。
6.Apacheの設定
# vi /etc/httpd/conf.d/vhost.conf
NameVirtualHost *:80
ServerName world.hoge.jp
DocumentRoot "/home/web-apps/world/web"
DirectoryIndex index.php
AllowOverride All
Allow from All
Alias /sf /usr/share/pear/data/symfony/web/sf
AllowOverride All
Allow from All
あとは、Apache起動させてOK.おなじみの画面でたし (*´∀`*)
参考:
Practical symfony | symfony | Web PHP Framework