Askeet_logo_bar

askeet links

WARNING: The SVN source code found in the release_day tags is outdated. Please refer to the current version until each day code is updated.

"day 1" links

symfony advent calendar

symfony advent calendar 1日目
プロジェクトの開始

課題

symfony advent calendarは、12月1日からクリスマスまで毎日発行される24のチュートリアルです。 そうです、新しいチュートリアルが毎日発行されるのです。 各チュートリアルは1時間以下程度のもので、symfonyを使った流行りのweb 2.0 アプリケーション 開発が体験できるでしょう。 クリスマスには完成したアプリケーションがオンライン上で見られるでしょう。そして、ソースコードはオープンソースにしました。このアプリケーションは利用可能で、興味深い、有用な面白いものになるでしょう。

1時間未満が24回と言うことは1日未満と同じ事です。また、それは正確には開発者がsymfonyを学習するのに必要とする時間だと私たちは思います。毎日、アプリケーションに新しい機能が加えられるでしょう。また、私たちは、あなたにsymfonyによるWEB開発のよい演習、symfonyの機能の利用方法を教えるためにこの開発を利用するでしょう。毎日、あなたはsymfonyによるWEBアプリケーション開発が早くて効率的だということを実感するでしょう。また、もっと知りたいと思うでしょう。

それが課題としては十分でないことを考えると、そしてまた、私たちは怠惰な人々であるので、私たちには21回目の日の計画がありません。コミュニティが最も必要とする機能はその日、ぶっつけ本番でアプリケーションに加えられます。そして、我々はそれを働かせます。

プロジェクト

チェックリスト、電話帳または本屋のような設計されたアプリケーションはたいていつまらない "展示品"アプリケーションです。しかし、我々は多くの機能をもちボリュームもある、何か役に立つオリジナルなプロジェクトでsymfonyを使いたいと思います。ゴールは本当に、symfonyが複雑な状況で使われることができるということを証明すること、そして流儀と少しの努力で専門的なアプリケーションを開発することです。

さらに、私たちは、symfonyウェブサイトが重い負荷に耐えられることを知ってもらいたいので、多くの人々に実際にアプリケーションを使ってもらいたいと思っています。そのため、そのアプリケーションは実際のサービスをもたらす必要があり、既存のニーズに答え、あるいは新しいものを作り出す必要があるのです。ウェブサイトの立ち上げは実際の負荷テストになるでしょう。これはまた、あなたたちにこのサイトを digg/bookmark/blog してもらい、実生活でどれだけのアクセスに耐えられるか話題にして欲しいということです。

プロジェクトの内容はもう1日、秘密にしておきましょう。私たちはまだ注目のウェブ2.0アプリケーションについて話す前に、今日する事がたくさんあります。しかしながら、これから話を進めるにあたって私たちはこのアプリケーションの名前を必要とします。したがって、それをaskeetと呼ぶことにしましょう。

What for today

今日の目的は、アプリケーションをウェブ・ブラウザに表示させること、上級者向けの開発環境をセットアップすることです。これは、 symfonyの設置、アプリケーションの生成、ソースコードのバージョン管理システムのセットアップを含んでいます。

sIt should be easy for those who already followed the previous tutorials, and not very hard for others. And everyone should learn something new.

私たちは、apache、MySQLおよびPHP 5がインストールされた、Unixライクなシステムを想定しています。もし、あなたがWindowsシステムを使用するとしても、パニックしないでください。同じように素晴らしく働くでしょう。あなたはコマンドプロンプトの中で少数のコマンドをタイプするだけです。

Symfony のインストール

symfonyをインストールする最も簡単な方法は、 PEARパッケージを使う方法です。 しかしながら、channelを使うには、またsymfonyのchannelにアクセスするためには、 PEAR を1.4.0 以上にアップグレードする必要があります。 (PHP 5.1.0を使用していないなら、それはPEAR 1.4.5を含んでいます)

$ pear upgrade PEAR

Note:もしPEARを使って問題が生じるなら、 インストール の章を参照してください。

それでは、 symfony channelを加えてみましょう。

$ pear channel-discover pear.symfony-project.com

あなたは、そのすべての依存性と一緒にsymfonyの最新の安定したバージョンをインストールする準備ができています:

$ pear install symfony/symfony-beta

phingパッケージがインストールされていないなら、同様にそれをインストールする必要があるでしょう:

$ pear install http://phing.info/pear/phing-current.tgz

symfony がインストールできたか、バージョンを表示して確認しましょう。

$ symfony -V

この新しいコマンドライン・ツールで何ができるか知りたい場合は、利用可能なオプションをリストするためにsymfony -T とタイプしてください。さらに、tgzアーカイブあるいはsvnリポジトリからsymfonyをインストールする方法を知りたい場合はinstallation の章を見てください。 さらに、コミュニティーの寄稿によるthe symfony wikiに、PEARを使わないインストールについて詳しく書かれています。

プロジェクトのセットアップ

symfony では、同じデータモデルを共有しているアプリケーションは、プロジェクトにまとめられます。私たちはaskeetアプリケーションにはフロントエンドとバックエンドがあるという事を説明しました。なので私たちは2つのアプリケーションを作ることになります。プロジェクトはアプリケーションの骨組みであって、それは最初に作られなければなりません。そのためにあなたがすることはディレクトリを作ること、コマンドラインから symfony init-project を実行することだけです。

$ mkdir /home/sfprojects/askeet
$ cd /home/sfprojects/askeet
$ symfony init-project askeet

次はコマンドラインでsymfony init-app を実行し、フロントエンドアプリケーションを作成します。

$ symfony init-app frontend

なんと、早いことでしょう!

Note: Wondowsユーザーは スペースを含まないディレクトリ(Documents and Settingsなど以外)でsymfonyを走らせたり、新しいプロジェクトをセットアップしたほうがいいでしょう。

ウェブサービスの設定

ウェブサーバーの設定

新しいアプリケーションを利用できるようにApacheの設定を変更しましょう。ここでは、新しいアプリケーションをバーチャルホストとして登録するのがよい方法なので、その方法を説明します。しかしなから、もしAliasとしてそれを加えるのを好むならば、ウェブサーバーの設定の章を参照してください。

Apache/conf/ ディレクトリにあるhttpd.confを開き、以下の行を追加します。

<VirtualHost *:80>
  ServerName askeet
  DocumentRoot "/home/sfprojects/askeet/web"
  DirectoryIndex index.php
  Alias /sf /usr/local/lib/php/data/symfony/web/sf

  <Directory "/home/sfprojects/askeet/web">
   AllowOverride All
  </Directory>
</VirtualHost>

Note: /sf というエイリアスは PEAR のdataディレクトリを指し示さないといけません。それを決めるには、次のようにタイプしてください。pear config-show Symfonyアプリケーションは若干のイメージとjavascriptファイルを利用するのでこのフォルダにアクセスする必要があります。そして、それはデバッグツールバーとAjaxヘルパーを利用するのに必要です。

Windowsでは、あなたはAliasの行を次のような感じで置き換える必要があります。

  Alias /sf "C:\php\pear\data\symfony\web\sf"

ドメイン名の決定

ローカルのドメイン名としてaskeetという名前を定義します。

もしあなたがLinuxを使っているならば、/etc/hostsに定義します。もしあなたがWindows XPを使っているなら、このファイルはC:\WINDOWS\system32\drivers\etc\ というディレクトリにあります。

次の行を追加してください。

127.0.0.1         askeet

Note:これを行うには管理者権限が必要です。

もしあなたが新しいホストを定義することを望まないなら、Listen 句を追加し、別ポートであなたのウェブサイトを稼動させます。これによってあなたは localhostというドメインを使うことができます。

新しい設定をテストしましょう。

Apacheを再起動し、次のURLで新しいアプリケーションにアクセスできるか確認しましょう。

http://askeet/

Congratulations

Note: symfony は URLの/index.php/の部分を取り除くために mod_rewrite モジュールを使うことができます。もしそれを使いたくない、もしくは あなたのウェブサーバーに同等の機能がない場合は、web/ディレクトリにある.htaccessを削除することができます。もしあなたのApacheがmod_rewrite付きでコンパイルされていないなら、mod_rewriteがDSOとしてインストールされているか、そして次の行がhttpd.confに書かれているか確認しましょう。

AddModule mod_rewrite.c
LoadModule rewrite_module modules/mod_rewrite.so

スマートなURLについてはルーティングの章を参照してください。

また、開発環境のアプリケーションにアクセスできるか確認しましょう。次のURLをタイプしてください。

http://askeet/frontend_dev.php/

小さなアイコンを持つWebデバッグツールバーが右上に見られるでしょう。それはAlias sf/の設定が正しければ表示されます。

web debug toolbar

あなたがWindows環境でIISサーバーを動かしたいならば、セットアップは少し異なります。関連したチュートリアルで設定方法を見つけてください。

Subversion

なまけもののグッドプラクティスの1つは、既存のコードを壊すことを心配しないことです。私たちは速く動きたいし、修正がいまいちなら前のバージョンに戻したくなります。また複数人での開発もしたいですし、あなたにアプリケーションの毎日の最新バージョンにアクセスして欲しいので、私たちはソースバージョンコントロールを採用するつもりです。私たちは、このためにSubversionを使います。ここではあなたがSubversionサーバーをすでにインストールしたか、Subversionサーバーにアクセスできるものと仮定します。

まず、 askeet のためのレポジトリを作ります。

$ svnadmin create $SVNREP_DIR/askeet
$ svn mkdir -m "layout creation" file:///$SVNREP_DIR/askeet/trunk file:///$SVNREP_DIR/askeet/tags file:///$SVNREP_DIR/askeet/branches

次に、 cache/log/ の一時ファイルを消して、最初のインポートをします。

$ cd /home/sfprojects/askeet
$ rm -rf cache/*
$ rm -rf log/*
$ svn import -m "initial import" . file:///$SVNREP_DIR/askeet/trunk

元からあったアプリケーションディレクトリは削除してSVNからチェックアウトしたものを使いましょう。

$ cd /home/sfprojects
$ mv askeet askeet.origin
$ svn co file:///$SVNREP_DIR/askeet/trunk/ askeet/
$ ls askeet

$ rm -rf askeet.origin

ひとつやりのこした事があります。もしあなたの作業ディレクトリでコミットしたとき、あなたは cachelogといったディレクトリに入っている望んでいないファイルをコピーしてしまうかもしれません。なので無視するリストを明確にする必要があります。

$ cd /home/sfprojects/askeet
$ svn propedit svn:ignore cache

SVNで設定されたデフォルトのエディタが立ち上がります。コミット時にSVNが無視してもらうようにcache/ ディレクトリのサブディレクトリを追加します。

*

保存してエディタを閉じれば完了です。

log/ ディレクトリについても同じ手順を繰り返します。

$ svn propedit svn:ignore log

そして次の文字だけ入力します。

*

Webサーバーがcacheとlogディレクトリに書き込みできるようにパーミッションを調整します。

$ chmod 777 cache
$ chmod 777 log

Note: Windowsユーザーはsubversionのレポジトリを扱うのにTortoiseSVNというすばらしいクライアントが使えます。

もしあなたがソースバージョンコントロールについてもっと知りたいなら、symfony bookの プロジェクトの作成の章 を参照してください。

Note: askeet のSVNレポジトリは公開されています。あなたは次のURLでアクセスできます。

  http://svn.askeet.com/

進んでチェックアウトしてみてください。

今日のコードはコミットされていて、release_day_1 タグでチェックアウトすることができます。

  $ svn co http://svn.askeet.com/tags/release_day_1/ askeet/

また明日会いましょう。

さて、すでに1時間です!!わたしたちは話しすぎて、symfonyの学習者ために何も新しいことをしませんでした。ちょっと明日の予習をしておきましょう。

もしあなたが最新のaskeetニュースに触れたいならaskeetめーリングリストを購読する か、もしくはフォーラムを訪れてください。

それでは明日会いましょう!

symfony advent calendar 2日目: データモデルのセットアップl »

30 comments. add a comment.

gravatar icon
#1sapumal on 2005-12-01 at 05:26

Symfony is keeping the promises well. Viva Symfony.

gravatar icon
#2Wes on 2005-12-02 at 03:25

Go symfony!!!

gravatar icon
#3mornlee on 2005-12-03 at 04:20

Chinese:<a href="http://www.neokeen.com/mornlee/2005/12/02/1133533909359.html">Symfony Askeet项目实战教程(1):安装Symfony创建项目 </a>

gravatar icon
#4Paul on 2005-12-08 at 01:22

Quick instructions to getting your SVN setup for public access.

http://www.bernzilla.com/item.php?id=445

gravatar icon
#5EdgarM on 2005-12-10 at 10:14

Hi,
I am using windows xampp and cygwin bash.
when installing with bash, you have to chmd 777 cache log
as it is not writable.

gravatar icon
#6Bradigan on 2005-12-10 at 06:49

May as well post my How_To on here in case it will help someone else.
- Windows Users -
at your c:\> type the following:
set PHP_COMMAND=c:\php\php.exe
- Set the path to your PHP.exe file

then you can now do this:
cd c:\www\myaskeet\>c:\www\php\symfony> init-project askeet

The Project Has Now Been Created.
BTW, this project looks so promising! If I didn't care so much, I wouldn't try and get it going as hard as I'm trying.

gravatar icon
#7relative^ambition on 2005-12-10 at 10:47

Rock on symfony!

Bradigan get a decent server together and then try development.

gravatar icon
#8Jason on 2005-12-12 at 04:27

If you get the following error upon accessing your project using in debug URL..along the lines of:

"Strict Standards: strftime() [function.strftime]: It is not safe to rely on the system's timezone settings...blah blah"

You are likely running PHP5.1..and thus need to explicitly set appropriate timezone for your PHP installation - One way to do this is by editing php.ini and doing the below:

;Valid PHP.ini entry example below
date.timezone ="America/New_York"

[Note: for best results, move to New York first]

gravatar icon
#9Francois Zaninotto on 2005-12-12 at 10:16

Many of the installation issues are already solved somewhere in the forum. You should do a search there ("community" section, then click "forum") before posting your questions regarding installation here.

gravatar icon
#10charlie on 2005-12-15 at 03:14

After a couple of hours, trying to upgrade the pear package It was done! I installed symfony.

But when run symfony -V I got the same error as matthias:
Parse error: parse error, unexpected ',', expecting '(' in .../symfony.php on line 19.

Also after upgrading again the same error.
Someone a solution?

gravatar icon
#11fabien on 2005-12-15 at 07:43

charlie: looks like your command line is PHP4.

gravatar icon
#12Randall on 2006-01-04 at 07:17

I just added a Wiki page describing all the steps you need to go through for an install on Windows XP. This guide does not assume that you have any prerequisite package already installed:

http://www.symfony-project.com/trac/wiki/WindowsXPDevelopmentEnvironment

gravatar icon
#13infect on 2006-01-14 at 06:19

Bradigan, you need to add your pear directory to the php include path. It's actually really simple and shouldn't have taken long to figure out. You should never have to edit the files in order to get it working. See this thread for more info: http://www.symfony-project.com/forum/index.php/t/409/

gravatar icon
#14Timm on 2006-01-24 at 07:00

If you are on Mac OS X and have FileVault turned on then you will get a permission error because apache can not get into your home folder. Try moving the symfony project folder to somewhere else on your drive.

gravatar icon
#15Aaron Shafovaloff on 2006-01-27 at 05:19

I suggest using a screen capture tool and webcam to make a video tutorial, freely host it on archive.org, and made a video-podcast out of it.

gravatar icon
#16Robert on 2006-02-02 at 04:30

Most people turn off PHP Warnings, but in our development environment, we got this when going to http://askeet for the first time:

"Strict Standards: strftime() [function.strftime]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for '-5.0/no DST' instead in C:\php\PEAR\symfony\symfony\log\sfLog\file.class.php on line 272"

We're using Windows XP Pro sp2, APache 2.0.55 & manual zip install of Php 5.1.2 with php-ini-recommended as php.ini.

Otherwise, the process has been a cinch so far for this day 1 tutorial.

gravatar icon
#17Robert on 2006-02-02 at 04:56

Oops, resolved comment #8 by adding this to php.ini file:

date.timezone = America/New_York

gravatar icon
#18Colin Smillie on 2006-02-09 at 10:36

On FC4 with PHP5 you might also need to install php-xml to get propel working. This can normally be done with "yum install php-xml".

gravatar icon
#19Giao Trinh on 2006-03-04 at 06:10

if you got a message "Fatal error: main(): Failed opening required 'pake/pakeException.class.php'..."
while running command "symfony -V" on Windows,
goto your PEAR folder and try again

gravatar icon
#20TheGuru on 2006-03-04 at 10:50

If you have trouble connecting PHP5/Apache/MySQL5 (on Windows0, all you need to do is:
- uncomment the line "extension=php_mysql.dll"
- set the extension dir as "extension_dir = "c:/php5.1.2/ext"
(replace with your php installtion directory name here)
- copy the <MYSQL_DIR>\bin\libMySQL.dll to C:\windows or system32 directory
- restart apache server

that's all you have to do.

gravatar icon
#21TheGuru on 2006-03-04 at 10:51

I forgot to mention in my previous post that, all those changes need to be done in "php.ini" file located in your PHP installation directory.

gravatar icon
#22misterclean on 2006-03-06 at 10:38

People, seriously, you need to stop using Windows! You are PROFESSIONAL software developers. Come on!

gravatar icon
#23robert on 2006-03-07 at 09:48

*dons flame-retardent suit*

I've been trying to make sense of subversion as it relates to day one.

Svn's book suggest that one should create a repository first, create a directory structure for a project with tags, branches, and trunk, import that project into the repository, and then check it out to begin using it.

This method creates one repository which holds multiple projects.

ie.

/repos/ ----> REPOSITORY
/askeet/
/tags
/branches
/trunk
/doeet/
/tags
/branches
/trunk

The svn directions from day 1 seem to suggest that we build a new repository per project.
ie.

/repos/askeet/ ----> REPOSITORY
/tags
/branches/
/trunk

/repos/doeet/ ----> REPOSITORY
/tags
/branches
/trunk

Since I'm on DAY ONE, and I'm a novice, which way is more efficient, or the professional standard?

As it stands, I'm following the instructions given here - since I don't want to get confused running these tutorials using a different tree structure.

Thanks in advance,

gravatar icon
#24krackerbelin on 2006-03-12 at 08:13

Phing has now a pear channel:

pear channel-discover pear.phing.info
pear install phing/phing

gravatar icon
#25James on 2006-03-13 at 05:36

I'm using MacOSX 10.4.5, I've managed to get most of it installed properly. I've changed my httpd.conf file so it say's:

<VirtualHost *:81>
ServerName askeet
DocumentRoot "~/sfprojects/askeet/web"
DirectoryIndex index.php

Alias /sf "/usr/local/php5/lib/php/data/symfony/web/sf"

<Directory "~/sfprojects/askeet/web">
AllowOverride All
</Directory>
</VirtualHost>

But I get a 404 (nb: I've changed my default port to 81 as I already have another type of web server running).

Any ideas?

gravatar icon
#26Joshua McMichael on 2006-03-14 at 05:55

Use the full path for DocumentRoot, e.g. /Users/[homedir]/sfprojects/askeet/web. Apache will be running as the www or apache user, and won't know the context for ~/.

Josh

gravatar icon
#27charlie on 2006-04-03 at 03:54

Indeed is PHP cli version 4 not working. Thanx for pointing out.
php5 is working very good!

gravatar icon
#28Phil on 2006-05-04 at 05:59

If you run into problems getting the "congratulations" page, try setting 'SF_DEBUG' in project/web/index.php on true. In my case I had to disable magic_quotes, register_globals and eaccelerator.

gravatar icon
#29Edin on 2006-05-10 at 02:21

On MacOSX 10.4.6 with apache2-2.2.0 from darwinports I had to put Allow from any into Directive part to avoid Forbidden apache page.

gravatar icon
#30jash on 2006-06-07 at 11:21

I got this error:

Fatal error: Class 'sfPhpConfigHandler' not found

Turned out that I had to turn off zend.ze1_compatibility_mode I had turned it off in the CLI php.ini but not in the apache php.ini.

SUSE 10.1 and Gentoo have separate php.ini files for the CLI and Apache