2015年6月20日土曜日

Laravel使ってみよう

まずはSqaleのLaravel導入マニュアルを見る。
Composerが必要らしいので、まずは開発環境のMacBook Proに導入する。
コマンドは下記の通り。

% curl -s http://getcomposer.org/installer | php 
#!/usr/bin/env php
All settings correct for using Composer
Downloading...

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

 
とりあえずホームディレクトリじゃ困るので場所を移動する。

% mv composer.phar <プロジェクトディレクトリ>/
※プロジェクトディレクトリはSqaleからGit Cloneしたディレクトリのこと 

次にSqaleの別のマニュアルを参照してcomposerを入れる。
 
% cd <プロジェクトディレクトリ>/
% php composer.phar self-update
You are already using composer version 89540c5690c439a3c9d35f689d3d6cca8d05642c. 
% php composer.phar install
Composer could not find a composer.json file in /Users/himi/buratabi-sqale
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section



なるほど、もう入ってるのか。。。知らなかった。

それではcomposerを使ってLaravelを入れてみる。

% php composer.phar create-project laravel/laravel sample-laravel --prefer-dist 
Installing laravel/laravel (v5.1.1)
  - Installing laravel/laravel (v5.1.1)
    Downloading: 100%        
    Downloading: 100%        
    Downloading: 100%        
    Failed to download laravel/laravel from dist: The "https://api.github.com/repos/laravel/laravel/zipball/136d7fa8ef74d0bbe3dd29c0e19c58585e84606e" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
    Now trying to download from source
  - Installing laravel/laravel (v5.1.1)
    Cloning 136d7fa8ef74d0bbe3dd29c0e19c58585e84606e

Created project in sample-laravel
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing vlucas/phpdotenv (v1.1.1)
    Downloading: 100%        
    Downloading: 100%        
    Downloading: 100%        
    Failed to download vlucas/phpdotenv from dist: The "https://api.github.com/repos/vlucas/phpdotenv/zipball/0cac554ce06277e33ddf9f0b7ade4b8bbf2af3fa" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
    Now trying to download from source
  - Installing vlucas/phpdotenv (v1.1.1)
    Cloning 0cac554ce06277e33ddf9f0b7ade4b8bbf2af3fa

  - Installing symfony/var-dumper (v2.7.1)
    Downloading: 100%        
    Downloading: 100%        
    Downloading: 100%        
    Failed to download symfony/var-dumper from dist: The "https://api.github.com/repos/symfony/var-dumper/zipball/c509921f260353bf07b257f84017777c8b0aa4bc" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
    Now trying to download from source
  - Installing symfony/var-dumper (v2.7.1)
    Cloning c509921f260353bf07b257f84017777c8b0aa4bc

  - Installing symfony/translation (v2.7.1)
    Downloading: 100%        
    Downloading: 100%        
    Downloading: 100%        
    Failed to download symfony/translation from dist: The "https://api.github.com/repos/symfony/Translation/zipball/8349a2b0d11bd0311df9e8914408080912983a0b" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
    Now trying to download from source
  - Installing symfony/translation (v2.7.1)
    Cloning 8349a2b0d11bd0311df9e8914408080912983a0b

  - Installing symfony/routing (v2.7.1)
    Downloading: 100%        
    Downloading: 100%        
    Downloading: 100%        
    Failed to download symfony/routing from dist: The "https://api.github.com/repos/symfony/Routing/zipball/5581be29185b8fb802398904555f70da62f6d50d" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
    Now trying to download from source
  - Installing symfony/routing (v2.7.1)
    Cloning 5581be29185b8fb802398904555f70da62f6d50d

  - Installing symfony/process (v2.7.1)
    Downloading: 100%        
    Downloading: 100%        
    Downloading: 100%        
    Failed to download symfony/process from dist: The "https://api.github.com/repos/symfony/Process/zipball/552d8efdc80980cbcca50b28d626ac8e36e3cdd1" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
    Now trying to download from source
  - Installing symfony/process (v2.7.1)
    Cloning 552d8efdc80980cbcca50b28d626ac8e36e3cdd1

  - Installing psr/log (1.0.0)
    Downloading: 100%        
    Downloading: 100%        
    Downloading: 100%        
    Failed to download psr/log from dist: The "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
    Now trying to download from source
  - Installing psr/log (1.0.0)
    Cloning fe0936ee26643249e916849d48e3a51d5f5e278b

  - Installing symfony/debug (v2.7.1)
    Downloading: 100%        
    Downloading: 100%        
    Downloading: 100%        
    Failed to download symfony/debug from dist: The "https://api.github.com/repos/symfony/Debug/zipball/075070230c5bbc65abde8241191655bbce0716e2" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
    Now trying to download from source
  - Installing symfony/debug (v2.7.1)
    Cloning 075070230c5bbc65abde8241191655bbce0716e2

  - Installing symfony/http-foundation (v2.7.1)
    Downloading: 100%        
    Downloading: 100%        
    Downloading: 100%        
    Failed to download symfony/http-foundation from dist: The "https://api.github.com/repos/symfony/HttpFoundation/zipball/4f363c426b0ced57e3d14460022feb63937980ff" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
    Now trying to download from source
  - Installing symfony/http-foundation (v2.7.1)
    Cloning 4f363c426b0ced57e3d14460022feb63937980ff

  - Installing symfony/event-dispatcher (v2.7.1)
    Downloading: 100%        
    Downloading: 100%        
    Downloading: 100%        
    Failed to download symfony/event-dispatcher from dist: The "https://api.github.com/repos/symfony/EventDispatcher/zipball/be3c5ff8d503c46768aeb78ce6333051aa6f26d9" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
    Now trying to download from source
  - Installing symfony/event-dispatcher (v2.7.1)
    Cloning be3c5ff8d503c46768aeb78ce6333051aa6f26d9

  - Installing symfony/http-kernel (v2.7.1)
    Downloading: 100%        
    Downloading: 100%        
    Downloading: 100%        
    Failed to download symfony/http-kernel from dist: The "https://api.github.com/repos/symfony/HttpKernel/zipball/208101c7a11e31933183bd2a380486e528c74302" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
    Now trying to download from source
  - Installing symfony/http-kernel (v2.7.1)
    Cloning 208101c7a11e31933183bd2a380486e528c74302


                                                                                                             
  [RuntimeException]                                                                                         
  Failed to clone git@github.com:symfony/HttpKernel.git via git, https, ssh protocols, aborting.             
  - git://github.com/symfony/HttpKernel.git                                                                  
    Cloning into '/Users/himi/buratabi-sqale/sample-laravel/vendor/symfony/http-kernel'...                   
    fatal: Unable to look up github.com (port 9418) (nodename nor servname provided, or not known)           
  - https://github.com/symfony/HttpKernel.git                                                                
    Cloning into '/Users/himi/buratabi-sqale/sample-laravel/vendor/symfony/http-kernel'...                   
    fatal: unable to access 'https://github.com/symfony/HttpKernel.git/': Could not resolve host: github.com 
  - git@github.com:symfony/HttpKernel.git                                                                    
    Cloning into '/Users/himi/buratabi-sqale/sample-laravel/vendor/symfony/http-kernel'...                   
    ssh: Could not resolve hostname github.com: nodename nor servname provided, or not known                 
    fatal: Could not read from remote repository.                                                            
                                                                                                             
    Please make sure you have the correct access rights                                                      
    and the repository exists.                                                                               
                                                                                                             


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] [--ignore-platform-reqs] [package] [directory] [version]

なるほど。とりあえず色々とエラーは出たが、下記はインストール出来た模様。


  • laravel/laravel (v5.1.1)
  • vlucas/phpdotenv (v1.1.1)
  • symfony/var-dumper (v2.7.1)
  • symfony/translation (v2.7.1)
  • symfony/routing (v2.7.1)
  • symfony/process (v2.7.1)
  • psr/log (1.0.0)
  • symfony/debug (v2.7.1)
  • symfony/http-foundation (v2.7.1)
  • symfony/event-dispatcher (v2.7.1)
  • symfony/http-kernel (v2.7.1)

sample-laravelというフォルダが出来ている。

% ls -a 
.        .DS_Store    composer.phar    orig        sample-laravel
..        .git        database    public


なんか、最後にRuntimeExceptionが出ているのが気になる。どうやらgithub.comが名前解決出来ていないっぽいが、、、

$ nslookup github.com 
Server:     192.168.128.1
Address:    192.168.128.1#53

Non-authoritative answer:
Name:    github.com
Address: 192.30.252.130


出来てるじゃん。。。
もういっかいcreate-projectしてみる。

$ php composer.phar create-project laravel/laravel sample-laravel --prefer-distInstalling laravel/laravel (v5.1.1)


                                                  
  [InvalidArgumentException]                      
  Project directory sample-laravel/ is not empty. 

                                                  


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] [--ignore-platform-reqs] [package] [directory] [version]

今度はsample-laravelディレクトリが空じゃ無いって怒られた・・・orz

一度ディレクトリを消して再試行。

$ php composer.phar create-project laravel/laravel sample-laravel --prefer-dist 
Installing laravel/laravel (v5.1.1)
  - Installing laravel/laravel (v5.1.1)
    Downloading: 100%        

Created project in sample-laravel
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing vlucas/phpdotenv (v1.1.1)
    Downloading: 100%        

  - Installing symfony/var-dumper (v2.7.1)
    Downloading: 100%        

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

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

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

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

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

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

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

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

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

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

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

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

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

  - Installing jakub-onderka/php-console-color (0.1)
    Downloading: 100%        

  - Installing jakub-onderka/php-console-highlighter (v0.3.2)
    Downloading: 100%        

  - Installing dnoegel/php-xdg-base-dir (0.1)
    Downloading: 100%        

  - Installing nikic/php-parser (v1.3.0)
    Downloading: 100%        

  - Installing psy/psysh (v0.4.4)
    Downloading: 100%        

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

  - Installing mtdowling/cron-expression (v1.0.4)
    Downloading: 100%        

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

  - Installing league/flysystem (1.0.4)
    Downloading: 100%        

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

  - Installing doctrine/inflector (v1.0.1)
    Downloading: 100%        

  - Installing danielstjules/stringy (1.9.0)
    Downloading: 100%        

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

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

  - Installing laravel/framework (v5.1.2)
    Downloading: 100%        

  - Installing fzaninotto/faker (v1.5.0)
    Downloading: 100%        

  - Installing hamcrest/hamcrest-php (v1.2.2)
    Downloading: 100%        

  - Installing mockery/mockery (0.9.4)
    Downloading: 100%        

  - Installing sebastian/version (1.0.5)
    Downloading: 100%        

  - Installing sebastian/global-state (1.0.0)
    Downloading: 100%        

  - Installing sebastian/recursion-context (1.0.0)
    Downloading: 100%        

  - Installing sebastian/exporter (1.2.0)
    Downloading: 100%        

  - Installing sebastian/environment (1.2.2)
    Downloading: 100%        

  - Installing sebastian/diff (1.3.0)
    Downloading: 100%        

  - Installing sebastian/comparator (1.1.1)
    Downloading: 100%        

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

  - Installing doctrine/instantiator (1.0.5)
    Downloading: 100%        

  - Installing phpdocumentor/reflection-docblock (2.0.4)
    Downloading: 100%        

  - Installing phpspec/prophecy (v1.4.1)
    Downloading: 100%        

  - Installing phpunit/php-text-template (1.2.0)
    Downloading: 100%        

  - Installing phpunit/phpunit-mock-objects (2.3.4)
    Downloading: 100%        

  - Installing phpunit/php-timer (1.0.6)
    Downloading: 100%        

  - Installing phpunit/php-token-stream (1.4.3)
    Downloading: 100%        

  - Installing phpunit/php-file-iterator (1.4.0)
    Downloading: 100%        

  - Installing phpunit/php-code-coverage (2.1.6)
    Downloading: 100%        

  - Installing phpunit/phpunit (4.7.4)
    Downloading: 100%        

  - Installing phpspec/php-diff (v1.0.2)
    Downloading: 100%        

  - Installing phpspec/phpspec (2.2.1)
    Downloading: 100%        

symfony/var-dumper suggests installing ext-symfony_debug ()
symfony/translation suggests installing symfony/config ()
symfony/routing suggests installing symfony/config (For using the all-in-one router or any 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/browser-kit ()
symfony/http-kernel suggests installing symfony/class-loader ()
symfony/http-kernel suggests installing symfony/config ()
symfony/http-kernel suggests installing symfony/dependency-injection ()
psy/psysh suggests installing ext-pcntl (Enabling the PCNTL extension makes PsySH a lot happier :))
psy/psysh suggests installing ext-pdo-sqlite (The doc command requires SQLite to work.)
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)
monolog/monolog suggests installing php-console/php-console (Allow sending log messages to Google Chrome)
league/flysystem suggests installing predis/predis (Allows you to use Predis for caching)
league/flysystem suggests installing league/flysystem-eventable-filesystem (Allows you to use EventableFilesystem)
league/flysystem suggests installing league/flysystem-rackspace (Allows you to use Rackspace Cloud Files)
league/flysystem suggests installing league/flysystem-copy (Allows you to use Copy.com storage)
league/flysystem suggests installing league/flysystem-azure (Allows you to use Windows Azure Blob storage)
league/flysystem suggests installing league/flysystem-webdav (Allows you to use WebDAV storage)
league/flysystem suggests installing league/flysystem-aws-s3-v2 (Allows you to use S3 storage with AWS SDK v2)
league/flysystem suggests installing league/flysystem-aws-s3-v3 (Allows you to use S3 storage with AWS SDK v3)
league/flysystem suggests installing league/flysystem-dropbox (Allows you to use Dropbox storage)
league/flysystem suggests installing league/flysystem-cached-adapter (Flysystem adapter decorator for metadata caching)
league/flysystem suggests installing league/flysystem-sftp (Allows you to use SFTP server storage via phpseclib)
league/flysystem suggests installing league/flysystem-ziparchive (Allows you to use ZipArchive adapter)
laravel/framework suggests installing aws/aws-sdk-php (Required to use the SQS queue driver and SES mail driver (~3.0).)
laravel/framework suggests installing doctrine/dbal (Required to rename columns and drop SQLite columns (~2.4).)
laravel/framework suggests installing guzzlehttp/guzzle (Required to use the Mailgun and Mandrill mail drivers (~5.3|~6.0).)
laravel/framework suggests installing iron-io/iron_mq (Required to use the iron queue driver (~2.0).)
laravel/framework suggests installing league/flysystem-aws-s3-v3 (Required to use the Flysystem S3 driver (~1.0).)
laravel/framework suggests installing league/flysystem-rackspace (Required to use the Flysystem Rackspace driver (~1.0).)
laravel/framework suggests installing pda/pheanstalk (Required to use the beanstalk queue driver (~3.0).)
laravel/framework suggests installing predis/predis (Required to use the redis cache and queue drivers (~1.0).)
laravel/framework suggests installing pusher/pusher-php-server (Required to use the Pusher broadcast driver (~2.0).)
fzaninotto/faker suggests installing ext-intl (*)
sebastian/global-state suggests installing ext-uopz (*)
phpdocumentor/reflection-docblock suggests installing dflydev/markdown (~1.0)
phpdocumentor/reflection-docblock suggests installing erusev/parsedown (~1.0)
phpunit/php-code-coverage suggests installing ext-xdebug (>=2.2.1)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
phpspec/phpspec suggests installing phpspec/nyan-formatters (~1.0 – Adds Nyan formatters)
Writing lock file
Generating autoload files
Generating optimized class loader
Application key [QbOibqGs7EAJod2w7Cqx29ZbkhRKHGkc] set successfully.


出来た!!

<追記1>
ところで、何か理解が間違っていたっぽい。
上記で作ったsample-laravelのディレクトリ自体を後付けでSqaleに追加出来るのかな?とりあえず、Sqale上で新たにアプリを作り、そちらでテストしてみる。

% mv sample-laravel ../<プロジェクトディレクトリ2>
% cd ../<プロジェクトディレクトリ2>

Sqale で Laravel を利用するの通りに進める。

% git init 
Initialized empty Git repository in /Users/himi/buratabi-laravel/.git/
% git add .
% git commit -m "The first commit"

 [master (root-commit) 44af938] The first commit
 73 files changed, 5452 insertions(+)
 create mode 100644 .env.example
 create mode 100644 .gitattributes
 create mode 100644 .gitignore
 create mode 100644 app/Console/Commands/Inspire.php
(中略)

 create mode 100644 tests/TestCase.php

ここで.gitignoreをいじり、"/vendor"のところをコメントアウトする。

% vi .gitignore
#/vendor
/node_modules
.env

% git add .
warning: CRLF will be replaced by LF in vendor/mockery/mockery/.styleci.yml.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in vendor/monolog/monolog/.php_cs.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in vendor/psy/psysh/.styleci.yml.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in vendor/swiftmailer/swiftmailer/tests/_samples/charsets/iso-2022-jp/one.txt.
The file will have its original line endings in your working directory.

$ git commit -m "Fixed .gitignore"[master 885baf7] Fixed .gitignore
warning: CRLF will be replaced by LF in vendor/mockery/mockery/.styleci.yml.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in vendor/monolog/monolog/.php_cs.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in vendor/psy/psysh/.styleci.yml.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in vendor/swiftmailer/swiftmailer/tests/_samples/charsets/iso-2022-jp/one.txt.
The file will have its original line endings in your working directory.
 5199 files changed, 588919 insertions(+), 1 deletion(-)
 create mode 100644 vendor/autoload.php
(中略)
 create mode 100644 vendor/vlucas/phpdotenv/src/Dotenv.php

% git remote add sqale ssh://sqale@gateway.sqale.jp:2222/<ユーザ名>/<プロジェクト名2>.git 
% git push -f sqale masterCounting objects: 6233, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5912/5912), done.
Writing objects: 100% (6233/6233), 5.61 MiB | 1.16 MiB/s, done.
Total 6233 (delta 1623), reused 0 (delta 0)
remote:
To ssh://sqale@gateway.sqale.jp:2222/hideyuki1977/buratabi-laravel.git
 + f37f933...885baf7 master -> master (forced update)

Sqaleのダッシュボードでデプロイ状況を確認すると、これで出来たっぽい。早速ウェブにアクセスしてみると、、、
 
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /home/sqale/current/public/index.php on line 50

がーん。次はソースを直すのかな。。。

<追記2>
これはclassという定数名?がPHP5.5以上でしか使えない事によるエラーみたい。
SqaleのPHPを5.5にアップデート出来るのかな。

0 件のコメント:

コメントを投稿