page_adsence

2014年11月6日木曜日

Laravelのインストール

比較的あたらしめのフレームワークであるLaravelを開発環境にインストールしてみた。

システム要件としては以下の通り。
PHP5.4.0以上
Mcrypt
PDO

さっそくインストールしてみる。
まずはcomposerのインストールから。

インストールコマンドは以下の通り。
$ curl -sS https://getcomposer.org/installer | php
#!/usr/bin/env php
All settings correct for using Composer
Downloading...

Composer successfully installed to: /Users/phpuser/tmp/composer.phar
Use it: php composer.phar

あとはパスが通っているディレクトリへ移動させる。
$ sudo mv composer.phar /usr/local/bin/composer

これでcomposerのインストールは完了。

続いてLaravelのインストール、というかプロジェクトの初期化をする。

$ composer create-project laravel-ja/laravel プロジェクト名 --prefer-dist
Installing laravel-ja/laravel (v4.2.8)
  - Installing laravel-ja/laravel (v4.2.8)
    Downloading: 100%

Created project in test
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing symfony/translation (v2.5.5)
    Downloading: 100%

  - Installing symfony/security-core (v2.5.5)
    Downloading: 100%

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

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

  - Installing psr/log (1.0.0)
    Downloading: 100%

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

  - Installing symfony/http-foundation (v2.5.5)
    Downloading: 100%

  - Installing symfony/event-dispatcher (v2.5.5)
    Downloading: 100%

  - Installing symfony/http-kernel (v2.5.5)
    Downloading: 100%

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

  - Installing symfony/dom-crawler (v2.5.5)
    Downloading: 100%

  - Installing symfony/css-selector (v2.5.5)
    Downloading: 100%

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

  - Installing symfony/browser-kit (v2.5.5)
    Downloading: 100%

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

  - Installing stack/builder (v1.0.2)
    Downloading: 100%

  - Installing predis/predis (v0.8.7)
    Downloading: 100%

  - Installing phpseclib/phpseclib (0.3.8)
    Downloading: 100%

  - Installing patchwork/utf8 (v1.1.25)
    Downloading: 100%

  - Installing nesbot/carbon (1.13.0)
    Downloading: 100%

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

  - Installing nikic/php-parser (v0.9.5)
    Downloading: 100%

  - Installing jeremeamia/superclosure (1.0.1)
    Downloading: connection...
Could not fetch https://api.github.com/repos/jeremeamia/super_closure/zipball/d05400085f7d4ae6f20ba30d36550836c0d061e8, enter your GitHub credentials to go over the API rate limit
The credentials will be swapped for an OAuth token stored in /home/username/.composer/auth.json, your password will not be stored
To revoke access to this token you can visit https://github.com/settings/applications
Username: git_username
Password:
Token successfully created
Failed to download jeremeamia/SuperClosure from dist: The "https://api.github.com/authorizations" file could not be downloaded (HTTP/1.1 404 Not Found)
Now trying to download from source
  - Installing jeremeamia/superclosure (1.0.1)
    Cloning d05400085f7d4ae6f20ba30d36550836c0d061e8

  - Installing filp/whoops (1.1.2)
    Downloading: 100%

  - Installing ircmaxell/password-compat (1.0.3)
    Downloading: 100%

  - Installing d11wtq/boris (v1.0.8)
    Downloading: 100%

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

  - Installing classpreloader/classpreloader (1.0.2)
    Downloading: 100%

  - Installing laravel/framework (v4.2.11)
    Downloading: 100%

symfony/translation suggests installing symfony/config ()
symfony/translation suggests installing symfony/yaml ()
symfony/security-core suggests installing symfony/validator (For using the user password constraint)
symfony/security-core suggests installing symfony/expression-language (For using the expression voter)
symfony/routing suggests installing symfony/config (For using the all-in-one router or any loader)
symfony/routing suggests installing symfony/yaml (For using the YAML loader)
symfony/routing suggests installing symfony/expression-language (For using expression matching)
symfony/routing suggests installing doctrine/annotations (For using the annotation loader)
symfony/event-dispatcher suggests installing symfony/dependency-injection ()
symfony/http-kernel suggests installing symfony/class-loader ()
symfony/http-kernel suggests installing symfony/config ()
symfony/http-kernel suggests installing symfony/dependency-injection ()
predis/predis suggests installing ext-phpiredis (Allows faster serialization and deserialization of the Redis protocol)
phpseclib/phpseclib suggests installing ext-mcrypt (Install the Mcrypt extension in order to speed up a wide variety of cryptographic operations.)
phpseclib/phpseclib suggests installing pear-pear/PHP_Compat (Install PHP_Compat to get phpseclib working on PHP < 4.3.3.)
patchwork/utf8 suggests installing ext-intl (Use Intl for best performance)
patchwork/utf8 suggests installing ext-mbstring (Use Mbstring for best performance)
monolog/monolog suggests installing graylog2/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 videlalvaro/php-amqplib (Allow sending log messages to an AMQP server using php-amqplib)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)
d11wtq/boris suggests installing ext-posix (*)
laravel/framework suggests installing doctrine/dbal (Allow renaming columns and dropping SQLite columns.)
Writing lock file
Generating autoload files
Mcrypt PHP extension required.
Script php artisan clear-compiled handling the post-install-cmd event returned with an error



  [RuntimeException]
  Error Output:



create-project [-s|--stability="..."] [--prefer-source] [--prefer-dist] [--repository-url="..."] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--keep-vcs] [--no-install] [package] [directory] [version]

mcryptがないのでエラーになった。
mcryptをインストール。
$ sudo yum install php-mcrypt
もう一回試す。
$ composer create-project laravel-ja/laravel test --prefer-dist
Installing laravel-ja/laravel (v4.2.8)
  - Installing laravel-ja/laravel (v4.2.8)
    Loading from cache

Created project in test2
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing symfony/translation (v2.5.5)
    Loading from cache

  - Installing symfony/security-core (v2.5.5)
    Loading from cache

  - Installing symfony/routing (v2.5.5)
    Loading from cache

  - Installing symfony/process (v2.5.5)
    Loading from cache

  - Installing psr/log (1.0.0)
    Loading from cache

  - Installing symfony/debug (v2.5.5)
    Loading from cache

  - Installing symfony/http-foundation (v2.5.5)
    Loading from cache

  - Installing symfony/event-dispatcher (v2.5.5)
    Loading from cache

  - Installing symfony/http-kernel (v2.5.5)
    Loading from cache

  - Installing symfony/finder (v2.5.5)
    Loading from cache

  - Installing symfony/dom-crawler (v2.5.5)
    Loading from cache

  - Installing symfony/css-selector (v2.5.5)
    Loading from cache

  - Installing symfony/console (v2.5.5)
    Loading from cache

  - Installing symfony/browser-kit (v2.5.5)
    Loading from cache

  - Installing swiftmailer/swiftmailer (v5.3.0)
    Loading from cache

  - Installing stack/builder (v1.0.2)
    Loading from cache

  - Installing predis/predis (v0.8.7)
    Loading from cache

  - Installing phpseclib/phpseclib (0.3.8)
    Loading from cache

  - Installing patchwork/utf8 (v1.1.25)
    Loading from cache

  - Installing nesbot/carbon (1.13.0)
    Loading from cache

  - Installing monolog/monolog (1.11.0)
    Loading from cache

  - Installing nikic/php-parser (v0.9.5)
    Loading from cache

  - Installing jeremeamia/superclosure (1.0.1)
    Downloading: 100%

  - Installing filp/whoops (1.1.2)
    Loading from cache

  - Installing ircmaxell/password-compat (1.0.3)
    Loading from cache

  - Installing d11wtq/boris (v1.0.8)
    Loading from cache

  - Installing symfony/filesystem (v2.5.5)
    Loading from cache

  - Installing classpreloader/classpreloader (1.0.2)
    Loading from cache

  - Installing laravel/framework (v4.2.11)
    Loading from cache

symfony/translation suggests installing symfony/config ()
symfony/translation suggests installing symfony/yaml ()
symfony/security-core suggests installing symfony/validator (For using the user password constraint)
symfony/security-core suggests installing symfony/expression-language (For using the expression voter)
symfony/routing suggests installing symfony/config (For using the all-in-one router or any loader)
symfony/routing suggests installing symfony/yaml (For using the YAML loader)
symfony/routing suggests installing symfony/expression-language (For using expression matching)
symfony/routing suggests installing doctrine/annotations (For using the annotation loader)
symfony/event-dispatcher suggests installing symfony/dependency-injection ()
symfony/http-kernel suggests installing symfony/class-loader ()
symfony/http-kernel suggests installing symfony/config ()
symfony/http-kernel suggests installing symfony/dependency-injection ()
predis/predis suggests installing ext-phpiredis (Allows faster serialization and deserialization of the Redis protocol)
phpseclib/phpseclib suggests installing pear-pear/PHP_Compat (Install PHP_Compat to get phpseclib working on PHP < 4.3.3.)
patchwork/utf8 suggests installing ext-intl (Use Intl for best performance)
patchwork/utf8 suggests installing ext-mbstring (Use Mbstring for best performance)
monolog/monolog suggests installing graylog2/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 videlalvaro/php-amqplib (Allow sending log messages to an AMQP server using php-amqplib)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)
d11wtq/boris suggests installing ext-posix (*)
laravel/framework suggests installing doctrine/dbal (Allow renaming columns and dropping SQLite columns.)
Writing lock file
Generating autoload files
PHP Fatal error:  Class 'PDO' not found in /home/username/sites/n.jp/test2/app/config/database.php on line 16
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Class 'PDO' not found","file":"\/home\/username\/sites\/n.jp\/test2\/app\/config\/database.php","line":16}}Script php artisan clear-compiled handling the post-install-cmd event returned with an error



  [RuntimeException]
  Error Output: PHP Fatal error:  Class 'PDO' not found in /home/username/sites/n.jp/test2/app/config/database.php on line 16




create-project [-s|--stability="..."] [--prefer-source] [--prefer-dist] [--repository-url="..."] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--keep-vcs] [--no-install] [package] [directory] [version]

今度はPDOがないって怒られた
PDOをインストール
$ sudo yum install php-pdo

PDOをインストール後にもう一回
$ composer create-project laravel-ja/laravel test --prefer-dist
Installing laravel-ja/laravel (v4.2.8)
  - Installing laravel-ja/laravel (v4.2.8)
    Loading from cache

Created project in test2
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing symfony/translation (v2.5.5)
    Loading from cache

  - Installing symfony/security-core (v2.5.5)
    Loading from cache

  - Installing symfony/routing (v2.5.5)
    Loading from cache

  - Installing symfony/process (v2.5.5)
    Loading from cache

  - Installing psr/log (1.0.0)
    Loading from cache

  - Installing symfony/debug (v2.5.5)
    Loading from cache

  - Installing symfony/http-foundation (v2.5.5)
    Loading from cache

  - Installing symfony/event-dispatcher (v2.5.5)
    Loading from cache

  - Installing symfony/http-kernel (v2.5.5)
    Loading from cache

  - Installing symfony/finder (v2.5.5)
    Loading from cache

  - Installing symfony/dom-crawler (v2.5.5)
    Loading from cache

  - Installing symfony/css-selector (v2.5.5)
    Loading from cache

  - Installing symfony/console (v2.5.5)
    Loading from cache

  - Installing symfony/browser-kit (v2.5.5)
    Loading from cache

  - Installing swiftmailer/swiftmailer (v5.3.0)
    Loading from cache

  - Installing stack/builder (v1.0.2)
    Loading from cache

  - Installing predis/predis (v0.8.7)
    Loading from cache

  - Installing phpseclib/phpseclib (0.3.8)
    Loading from cache

  - Installing patchwork/utf8 (v1.1.25)
    Loading from cache

  - Installing nesbot/carbon (1.13.0)
    Loading from cache

  - Installing monolog/monolog (1.11.0)
    Loading from cache

  - Installing nikic/php-parser (v0.9.5)
    Loading from cache

  - Installing jeremeamia/superclosure (1.0.1)
    Loading from cache

  - Installing filp/whoops (1.1.2)
    Loading from cache

  - Installing ircmaxell/password-compat (1.0.3)
    Loading from cache

  - Installing d11wtq/boris (v1.0.8)
    Loading from cache

  - Installing symfony/filesystem (v2.5.5)
    Loading from cache

  - Installing classpreloader/classpreloader (1.0.2)
    Loading from cache

  - Installing laravel/framework (v4.2.11)
    Loading from cache

symfony/translation suggests installing symfony/config ()
symfony/translation suggests installing symfony/yaml ()
symfony/security-core suggests installing symfony/validator (For using the user password constraint)
symfony/security-core suggests installing symfony/expression-language (For using the expression voter)
symfony/routing suggests installing symfony/config (For using the all-in-one router or any loader)
symfony/routing suggests installing symfony/yaml (For using the YAML loader)
symfony/routing suggests installing symfony/expression-language (For using expression matching)
symfony/routing suggests installing doctrine/annotations (For using the annotation loader)
symfony/event-dispatcher suggests installing symfony/dependency-injection ()
symfony/http-kernel suggests installing symfony/class-loader ()
symfony/http-kernel suggests installing symfony/config ()
symfony/http-kernel suggests installing symfony/dependency-injection ()
predis/predis suggests installing ext-phpiredis (Allows faster serialization and deserialization of the Redis protocol)
phpseclib/phpseclib suggests installing pear-pear/PHP_Compat (Install PHP_Compat to get phpseclib working on PHP < 4.3.3.)
patchwork/utf8 suggests installing ext-intl (Use Intl for best performance)
patchwork/utf8 suggests installing ext-mbstring (Use Mbstring for best performance)
monolog/monolog suggests installing graylog2/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 videlalvaro/php-amqplib (Allow sending log messages to an AMQP server using php-amqplib)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)
d11wtq/boris suggests installing ext-posix (*)
laravel/framework suggests installing doctrine/dbal (Allow renaming columns and dropping SQLite columns.)
Writing lock file
Generating autoload files
Generating optimized class loader
Compiling common classes
Compiling views
Application key [XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX] set successfully.

出来た。

インストール完了後は
プロジェクトルート/app/storage
のパーミッションを777に変更する

$ chmod -R 777 app/storage

app/storageの権限を変えていない場合、「Error in exception handler.」と表示される。

これらの作業が完了後にサイトを確認してみると、
「You have arrived.」というページが表示されている

Laravelは2回目以降のインストールはキャッシュから読み込むようになっているので、
一回サーバ内でインストールしておけば、毎回プロジェクトを作るたびにダウンロードする必要はない。
キャッシュはプロジェクトとは関係ない場所に保存されているので、Laravelのプロジェクトを全部消したとしても、
インストールに影響はない。

一番最初に行うのは、アプリケーションとデータベースの設定。
app/config/app.phpに書かれているArtisan(アルチザン)はコマンドラインインターフェイス。
app/config/database.phpには、SQL別に設定が書けるようになっている。とりあえず自分の使うタイプであるMySQL部分の設定だけ変更。