polidog lab++

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

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

Jan 9, 2014 | tech | composer php symfony2

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

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

1. composer.pharを用意する

$ 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を通します。

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

でsourceコマンドで反映する

$ source ~/.zshrc

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

$ mkdir hogeproject
$ cd hogeproject

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

$ composer.phar create-project symfony/framework-standard-edition ./
$ 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のビルトインサーバつかいませう

$ 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」にアクセスすればこんな感じにみれるはずです。
symfony2 start

参考

Installing and Configuring Symfony

comments powered by Disqus

関連記事

© 2017 polidog lab++