2015年8月30日日曜日

Laravel標準の認証機能を利用していてハマる

Laravel標準の認証機能でユーザ追加やログインの処理が出来るのは分かったが、認証された状態では/homeにリダイレクトされてしまい困る。

ここにリダイレクトする輩は、
  • ¥Illuminate¥Foundation¥Auth¥RedirectsUsers@redirectPath
  • ¥Illuminate¥Foundation¥Auth¥ResetsPasswords@redirectPath
  • app¥Http¥Middleware¥RedirectIfAuthenticated@handle
のお三方である。

最初の二つは、ユーザ認証・登録やパスワードリセットの操作の時のみに発動するっぽいので、最後のが怪しい。で、このクラスを呼んでいるファイルを調べると、app¥Http¥Kernelであった。$routeMiddlewareという変数にこのクラスが設定されている。何のことかと言うと、

Laravel 5 の Global Middleware ではルートの名前がとれない?

なるほど、「特定のルートに割り当てる Middleware」のことのようだ。そして、その解釈からすると、このクラスは guestという特定のルートに割り当てられている様だ。

(続く)

2015年8月16日日曜日

Laravel5標準の認証機能

ログインに成功すると/homeというパスにリダイレクトされる。

これは、RedirectsUsersトレイトのredirectPathメソッドにハードコードされている。

但し、上記メソッド内の実装の通り、下記のプロパティを順番に調べて、プロパティが存在すればそちらを代わりに返す事になっている。
  1. redirectPath
  2. redirectTo
なるほどね。

この場合、最終的に RedirectsUsersトレイトの実装を使っているクラスはAuthControllerなので、こちらに上記のプロパティどちらかを実装して値を設定すれば、ログイン後のリダイレクト先を/homeから変更出来るというわけ。

ちなみに、調べてみると両者は下記のクラスのredirectPathメソッド内 で参照されている。
  • Illuminate/Foundation/Auth/RedirectsUsers.php
  • Illuminate/Foundation/Auth/ResetsPasswords.php
で、なんで二つあるんだろうと思ったのだが、過去のLaravelの更新履歴を見ると、どうやらredirectPathが正しく、redirectToは歴史的な理由(もしくは、過去のLaravelを使っているコードとの互換性の関係)で残されているっぽい。

When to set redirectPath property in Laravel 5 auth trait

なるほどね〜。ソースを見ると色々な事が分かりますな。

Homesteadのmysql

HomesteadのMySQLにログインする時は、HomesteadのVM上で下記のコマンドを打つ。

% mysql -u root -psecret homestead

あとはSHOW TABLESするなりお好きに。

2015年8月15日土曜日

LaravelとPHPのトレイト(Trait)とView周り色々

最近のPHPにはトレイト(Trait)という機能がある。初めて知った。

PHP: トレイト - Manual

要は、多重継承出来ない PHPで、実装をうまく再利用する為の機能らしい。私はC++で多重継承の経験があるけれど、確かにあれはとっちらかってワケが分からなくなるので、単一継承の方が良いと思う(Javaが単一継承を選んだ時もそう思った)が、実装を再利用するにはちょっと不便なのも事実。

PHPのトレイトでは、メソッドだけで無くプロパティも設定出来たり、抽象メソッドも設定出来たりする。殆ど実体化(instantiate)出来ないだけのクラスって感じだな。

クラス内でトレイトを指定すると、現クラスの実装→トレイトの実装→親クラスの実装、という順番で優先順位が設定され実装がオーバーライドされる。

で、例えばLaravelのAuthControllerAuthenticatesAndRegistersUsersトレイトを使っている。このAuthenticatesAndRegistersUsersトレイトは、AuthenticatesUsersトレイトとRegistersUsersトレイトを使っている。このAuthenticatesUsersトレイトが、例えばgetLogin, postLogin, getLogout等のメソッドの実装を持っている。

getLoginの実装ではauth.authenticateというViewがあればそれを、無ければauth.loginというViewを返す。このauth.loginというViewの名前は、自動的にプロジェクト内の/resources/views/auth/login.blade.phpというパスに変換され、該当するファイルを表示する。

HTML Formの表示には、Laravel5ではオプションになったHTMLヘルパを使う事が出来る。

Laravel5で新規データの作成

HTMLタグで書く事も出来るが、ヘルパを使うメリットとしては、HTMLタグにPHPコードを埋め込む際にタイプ(文字)数が減るとか、そういうメリットがあるというところか。

2015年7月26日日曜日

Homestead上でLaravelアプリを開発するにあたって始め方がよう分からん

Homesteadをインストールしたは良いが、その後アプリを開発しようにもLaravelのファイルが無い。色々とググってみたが良く分からない。

そこで、HomesteadにログインしてcomposerでLaravelのプロジェクトを作成してみる事に。

% composer create-project laravel/laravel --prefer-dist <project name>
...(省略)...

そして、ホスト環境と共有されているフォルダにごっそりファイルをコピーする。

% cd ~/<project name>/
% cp -R .[a-z]* * ../Code/Laravel/

これでHomestead環境にHTTPアクセスすると、ちゃんとindex.phpが表示された。

しかし、何となくこの手順はキモいのだけれど、本当はどうやるべきなのか。

<追記>
しかし、とりあえずこれでLaravelエキスパート養成読本[モダンな開発を実現するPHPフレームワーク!]のチュートリアルで遊べる事が分かった。Laravel凄い。

Homesteadにログインする

ホスト環境(私の場合Mac)とフォルダが共有されているのは分かっていたが、シェルでログインするにはどうしたら良いのだろうかと調べてみるとこれがまた簡単。Vagrantって本当に凄いな。

vagrant sshと打てば良いらしい。

% vagrant ssh 
A Vagrant environment or target machine is required to run this
command. Run `vagrant init` to create a new Vagrant environment. Or,
get an ID of a target machine from `vagrant global-status` to run
this command on. A final option is to change to a directory with a
Vagrantfile and to try again.


なるほど、vagrant global-statusで取得したIDを指定しないといけないのね。

% vagrant global-status 
id       name    provider   state   directory                          
------------------------------------------------------------------------
884a4c3  default virtualbox running /Users/<username>/Homestead              

The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date. To interact with any of the machines, you can go to
that directory and run Vagrant, or you can use the ID directly
with Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"


なるほど、これか。早速指定してみる。


% vagrant ssh 884a4c3 
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-24-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Tue Oct 21 14:52:42 2014 from 10.0.2.2

vagrant@homestead:~%

おお。これだけでログイン出来てしまった。凄い便利だな。

Homesteadをインストールする

まず、VirtualBoxをインストール。MacOS向けのインストーラをここからダウンロードして実行するだけ。簡単。

次にVagrantをインストール。公式WebサイトのダウンロードページからMacOS向けのインストーラをダウンロードして実行するだけ。これも簡単。

% which vagrant/usr/local/bin/vagrant

なるほど、無事インストールされた模様。そこで更にHomesteadのインストール手順に従うと、、、

% vagrant box add laravel/homestead==> box: Loading metadata for box 'laravel/homestead'
    box: URL: https://atlas.hashicorp.com/laravel/homestead
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) virtualbox
2) vmware_desktop

Enter your choice: 1
==> box: Adding box 'laravel/homestead' (v0.2.7) for provider: virtualbox
    box: Downloading: https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.2.7/providers/virtualbox.box

==> box: Successfully added box 'laravel/homestead' (v0.2.7) for 'virtualbox'!

このダウンロードに結構時間が掛かる。大体1時間半くらいかかった。更にHomesteadをgit cloneする。

% git clone https://github.com/laravel/homestead.git HomesteadCloning into 'Homestead'...
remote: Counting objects: 1047, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 1047 (delta 2), reused 0 (delta 0), pack-reused 1036
Receiving objects: 100% (1047/1047), 158.21 KiB | 90.00 KiB/s, done.
Resolving deltas: 100% (606/606), done.
Checking connectivity... done.


さらにHomestead.yamlを作る。

% cd Homestead/
% sh init.sh
Homestead initialized!


更にHomestead.yamlを見ると、ProviderはVirtualBoxなので問題無し。

% cd ~/.homestead/
% grep provider Homestead.yaml 
provider: virtualbox

更にSSH Keyを作る。

% ssh-keygen -t rsa -C "you@homestead
"Generating public/private rsa key pair.
Enter file in which to save the key (/Users/<username>/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/<username>/.ssh/id_rsa.
Your public key has been saved in /Users/<username>/.ssh/id_rsa.pub.
...(中略)...


SSH Keyのファイル名を変える。

% cd ~/.ssh/
% mv id_rsa Homestead
% mv id_rsa.pub Homestead.pub


Homestead.yamlに色々と設定(以下、変えた所だけ)。

% cd ~/.homestead/
% vi Homestead.yaml
(前略)
ip: "192.168.11.11"
authorize: ~/.ssh/Homestead.pub
keys:    - ~/.ssh/Homestead
(後略)

さて、ここでHomesteadを立ち上げる

% vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'laravel/homestead' is up to date...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 80 => 8000 (adapter 1)
    default: 443 => 44300 (adapter 1)
    default: 3306 => 33060 (adapter 1)
    default: 5432 => 54320 (adapter 1)
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 4.3.14
    default: VirtualBox Version: 5.0
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/<username>/Homestead
    default: /home/vagrant/Code => /Users/<username>/<app name>
==> default: Running provisioner: file...
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: ssh-rsa XXXXX you@homestead
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Running provisioner: shell...
    default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-3a6mwz.sh
==> default: Running provisioner: shell...
    default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-1qvawnk.sh
==> default: nginx stop/waiting
==> default: nginx start/running, process 1823
==> default: php5-fpm stop/waiting
==> default: php5-fpm start/running, process 1838
==> default: Running provisioner: shell...
    default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-16v1opw.sh
==> default: Warning: Using a password on the command line interface can be insecure.
==> default: Running provisioner: shell...
    default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-1kgrvd.sh
==> default: createdb: database creation failed: ERROR:  database "homestead" already exists
==> default: Running provisioner: shell...
    default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-8nfae9.sh
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: php5-fpm stop/waiting
==> default: php5-fpm start/running, process 1928
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Updating to version c6cc6dd6070871f4b198ed39f76dd8047c116b02.
==> default:     Downloading: Connecting...
==> default:
==> default:     Downloading: 100%
==> default:        
==> default:
==> default: Use composer self-update --rollback to return to version c43a39f7334ae3df968cd36a6eff0436bea0da75
==> default: Running provisioner: shell...
    default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-5gwe60.sh


というわけで無事起動した模様。後は、/private/etc/hostsにhomestead.appを名前解決するエントリだけ追加して終了。

% cd /private/etc
% sudo vi hosts
Password: *****

エントリはこんな感じ。IPは~/.homestead/Homestead.yamlで設定したのに合わせる。

192.168.11.11   homestead.app

% ping homestead.app
PING homestead.app (192.168.11.11): 56 data bytes
64 bytes from 192.168.11.11: icmp_seq=0 ttl=64 time=0.650 ms
64 bytes from 192.168.11.11: icmp_seq=1 ttl=64 time=0.496 ms

.....

これでどうやら立ち上がった模様。

2015年7月18日土曜日

What's Forge!?

ForgeとかDigitalOceanとか、色々と登場するが、一体何なのか理解を整理する事に。

Laravel ForgeでさくらのVPSに環境を用意する

こちらを読むと、
  • Laravelが動く環境をわずかな作業で構築し管理できるサービス
  • 環境構築以外にも、gitプロジェクトのデプロイやcronスケジュール管理などもできる
ということで、DigitalOceanというホスティングサービス上にLaravelの環境を作ってくれるのがForgeということで、という事は常に最新版のLaravelを使える様にしてくれるって事なのかな。

ちなみに、こちらのページにはLaravel Homesteadについても記載があったので調べてみた。 Homesteadは、要するにLaravelを動かすのに必要なソフトがそっくり一式入った仮想マシンのイメージで、Vagrantを使ってVirtualBoxかVMWareの仮想マシン上にLaravelの開発環境を構築出来る様だ。


仮想環境構築ツール「Vagrant」で開発環境を仮想マシン上に自動作成する

良く知らなかったが、こういう仮想マシンの環境構築を自動で行うツールというのが普及している様だ。ということは、同じような技術を使えばForgeみたいなのも出来るわけだね。なるほど。

ちょっと今すぐにVirtualBoxを手元のMacに入れるのは難しいが、Homesteadも試してみたい。

<追記>

2015年6月20日土曜日

ForgeとDigitalOcean

とりあえずSqaleのPHPをバージョンアップするのは無理っぽいのと、そんなのに時間使いたくないので、サーバを乗り換える事にする。Sqaleは解約だな。

LaravelがやっているForgeというサービスと、格安VPS (?)のDigitalOceanを使う事に。

さっさとLaravel使い始めたい。

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にアップデート出来るのかな。

2015年6月14日日曜日

開発色々

こんな記事を発見した。

 PHPのフレームワークって色々とあるんですね。海外ではLaravelというのが急速に広まっている様ですが、日本ではまだCakePHPが人気のようです。どっちが良いのかな。ちなみに、どちらもSqaleで使う方法が載ってます。


どうやら、Laravelは自由度が高い分コードがとっちらかる様ですね。

どうなんでしょうね。IT技術については、結局日本も海外のトレンドに追従する事が多い気がするんで、やっぱLaravelなのかな。

あと、Gitの使い方にまだ慣れないのでこんな情報も。

備忘録でした。

2015年4月12日日曜日

SqaleのMySQL

Rackhubでは、MySQLを使う前に
  • CREATE DATABSE
  • CREATE USER
が必須だったわけだが、Sqaleではこれらが自動的にセットアップされるので、不要というかむしろこういったオペレーションは出来ない。早速CREATE TABLEする所から始めれば良いという事。

Sqaleではscpでファイル送り込めん

Sqaleではscpでファイルを送り込む事が出来ず(SSHでログイン出来るのに・・・)、gitかSFTPを使う必要がある。SFTPだとMacのコマンドラインからファイルを送り込むのが良く分からんので、gitを勉強するか。。。

とりあえずこの辺で勉強させて頂く。
サルでもわかるGit入門

<続報>
こちらも面白い。
そもそもGitHubとは一体何か?

<続報2>
なんか、GitHubでは無料ユーザがプライベートリポジトリを持てないらしいので、BitBucketにしようかと。というか、気付いたらGitHubにもBitBucketにもアカウント持ってた。何してたんだ>過去の俺

<続報3>
そもそも勘違いをしていた。SqaleでGitを使ってデプロイするというのは、つまりSqaleが設定するリポジトリを手元のMacにクローンし、そこにファイルを追加してコミットする事でSqaleにファイルがアップロードされる、ということの様だ

2015年4月5日日曜日

Sqale

とりあえずGMOペパポ (旧paper boy & co) のSqaleを使ってみる事に。15日無料との事。

2015年4月4日土曜日

Rackhubが突然のサービス終了

昨日こんなメールが来た。

いつもRackhubをご利用いただきありがとうございます。

2015年5月29日15:00をもちまして、
サービスを終了させていただくこととなりました。
Rackhubをご愛顧頂きましたお客さまには、
この様な結果となりましたことを心よりお詫び申し上げます。
申し訳ございません。

サービス終了に伴い、本日より課金処理を停止させていただき、
新規のRackの作成も停止させていただきます。
サービスの終了までにお客様のRackに保存されているデータに

ついては
お客様においてバックアップしていただきますようお願い申し上げ
ます。

--
Fluxflex, Inc.
残念だけれど移籍先を探さなくちゃ。。。