Featured image of post オシャレに格好良くsymfony2でプロジェクトを始めよう

オシャレに格好良くsymfony2でプロジェクトを始めよう

Twitter ツイート Hatena Bookmark ブックマーク

composer使えばオシャレに格好良くsymfony2でプロジェクトを始められるわけですよ。
ちょっと前なのかわかりませんが、僕がsymfony2を使おうと思ってた頃は、Symfony Standard Editionのtar.gzとかzipを落としてきて解凍するって記事が見受けられたんですが、最近は違うんすね。

ということでcomposer使ったインストール方法はこんな感じです。

1. composer.pharを用意する

1
2
3
4
5
6
7
$ curl -s https://getcomposer.org/installer | php
#!/usr/bin/env php
All settings correct for using Composer
Downloading...

Composer successfully installed to: /Users/polidog/bin/composer.phar
Use it: php composer.phar

で、あとはzshrcやbash_profileとかに適当にpathを通します。

1
2
3
$ vim ~/.zshrc
# 環境に応じて変更してくだされ
export PATH=~/bin:$PATH

でsourceコマンドで反映する

1
$ source ~/.zshrc

2. 適当にプロジェクトディレクトリを用意する

1
2
$ mkdir hogeproject
$ cd hogeproject

3. Composerを使ってSymfony Standard Editionをインストールする

1
$ composer.phar create-project symfony/framework-standard-edition ./
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
$ php composer.phar create-project symfony/framework-standard-edition path/ 2.4.1
Installing symfony/framework-standard-edition (v2.4.1)
  - Installing symfony/framework-standard-edition (v2.4.1)
    Downloading: 100%

Created project in ./
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing jdorn/sql-formatter (v1.2.16)
    Downloading: 100%

  - Installing psr/log (1.0.0)
    Loading from cache

  - Installing twig/twig (v1.15.0)
    Downloading: 100%

  - Installing doctrine/lexer (v1.0)
    Loading from cache

  - Installing doctrine/annotations (v1.1.2)
    Loading from cache

  - Installing doctrine/collections (v1.1)
    Loading from cache

  - Installing doctrine/cache (v1.3.0)
    Loading from cache

  - Installing doctrine/inflector (v1.0)
    Loading from cache

  - Installing doctrine/common (v2.4.1)
    Loading from cache

  - Installing symfony/symfony (v2.4.1)
    Downloading: 100%

  - Installing symfony/icu (v1.0.0)
    Loading from cache

  - Installing doctrine/dbal (v2.4.2)
    Downloading: 100%

  - Installing doctrine/doctrine-bundle (v1.2.0)
    Loading from cache

  - Installing kriswallsmith/assetic (v1.1.2)
    Loading from cache

  - Installing symfony/assetic-bundle (v2.3.0)
    Loading from cache

  - Installing sensio/framework-extra-bundle (v3.0.0)
    Downloading: 100%

  - Installing doctrine/orm (v2.4.1)
    Downloading: 100%

  - Installing twig/extensions (v1.0.1)
    Loading from cache

  - Installing swiftmailer/swiftmailer (v5.0.3)
    Downloading: 100%

  - Installing symfony/swiftmailer-bundle (v2.3.4)
    Loading from cache

  - Installing monolog/monolog (1.7.0)
    Downloading: 100%

  - Installing symfony/monolog-bundle (v2.4.1)
    Downloading: 100%

  - Installing sensio/distribution-bundle (v2.3.4)
    Loading from cache

  - Installing sensio/generator-bundle (v2.3.4)
    Loading from cache

  - Installing incenteev/composer-parameter-handler (v2.1.0)
    Downloading: 100%

kriswallsmith/assetic suggests installing leafo/lessphp (Assetic provides the integration with the lessphp LESS compiler)
kriswallsmith/assetic suggests installing leafo/scssphp (Assetic provides the integration with the scssphp SCSS compiler)
kriswallsmith/assetic suggests installing ptachoire/cssembed (Assetic provides the integration with phpcssembed to embed data uris)
kriswallsmith/assetic suggests installing leafo/scssphp-compass (Assetic provides the integration with the SCSS compass plugin)
monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing raven/raven (Allow sending log messages to a Sentry server)
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ruflin/elastica (Allow sending log messages to an Elastic Search server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
Writing lock file
Generating autoload files
Creating the "app/config/parameters.yml" file
Some parameters are missing. Please provide them.
database_driver (pdo_mysql):
database_host (127.0.0.1):
database_port (null):
database_name (symfony): hogetest
database_user (root):
database_password (null): hogehoge
mailer_transport (smtp):
mailer_host (127.0.0.1):
mailer_user (null):
mailer_password (null):
locale (en): ja
secret (ThisTokenIsNotSoSecretChangeIt): akkekakakak
Clearing the cache for the dev environment with debug true
Installing assets using the hard copy option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Acme\DemoBundle into web/bundles/acmedemo
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution

これでインストール完了です。

試しに実行してみる

試しに動かしてみます。最近Vagrant+Chefみたいな環境で開発している僕ですが、動作チェックぐらいなんでPHPのビルトインサーバつかいませう

1
2
3
4
5
6
$ cd web
$ php -S localhost:3000
PHP 5.4.9 Development Server started at Thu Jan  9 01:16:51 2014
Listening on http://localhost:3000
Document root is /Users/polidog/hogeproject/web
Press Ctrl-C to quit.

これでビルトインサーバ起動しました。
あとは「http://localhost:3000/app_dev.php」にアクセスすればこんな感じにみれるはずです。

参考

Installing and Configuring Symfony

comments powered by Disqus
Built with Hugo
テーマ StackJimmy によって設計されています。