vagrantでubuntuの起動が異常に遅い

vagrant upのときにsshが成功するのがやたら遅いので直してみました
遅くなったのはVagrantfileで固定IPを振ってからだと思います

vagrant は 1.6.5
ubuntu/trusty64のBoxを使っています

まずVagrantFileを修正してGUIモードで確認してみます

$ vim Vagrantfile

 config.vm.provider "virtualbox" do |vb|
    vb.gui = true
end

$ vagrant reload

cloud-init-nonet waiting 120 seconds for a network device

と出て2分もまって、エラーになってる
起動したら

$ vagrant ssh
$ vi /etc/network/interfaces

auto lo
iface lo inet loopback

+ auto eth0
+ iface eth0 inet dhcp

- source /etc/network/interfaces.d/*.cfg
+ # source /etc/network/interfaces.d/*.cfg

( + : 追加行、 – : 削除行)

/etc/network/interfaces.d/eth0.cfg
にdhcpが指定してあるんですが、うまくひけないっぽい

cloud-initのバグらしいです
結構、はまりました

phpで配列の先頭を取得する

phpで配列の先頭を取得できる関数に

array_shift

がありますが、これは配列から要素を抜いてしまいます(破壊的な関数)

$arr = ['first' => 1, 'second' => 2];

$top = array_shift($arr);
var_dump($top);
// int(1)
var_dump($arr);
/*
配列が小さくなった!
array(1) {
  'second' =>
  int(2)
}
*/

破壊せずに取りたかったら

reset

を使いましょう

$arr = ['first' => 1, 'second' => 2];

$top = reset($arr);
var_dump($top);
int(1)
array(2) {
  'first' =>
  int(1)
  'second' =>
  int(2)
}

UbuntuのbashがCtrl+sで固まらないようにする

Ubuntuのbashで作業していて
Ctrl+s
を押してしまうと画面がかたまります

戻るには
Ctrl+q
を押せば戻れるのですが不便です

$ stty -a
をみると

stop = ^S;

とstopにCtrl + sが割り当たっているからなので

$ stty stop undef
としてしまえば無効になります

常に無効にしたかったら

~/.bashrc

stty stop undef
を書き込んでしまえばいいです

gem install mysql2でエラー

$ gem install mysql2
でエラー発生

[code lang=text]
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/home/vagrant/.rbenv/versions/2.2.0/bin/$(RUBY_BASE_NAME)
–with-mysql-dir
–without-mysql-dir
–with-mysql-include
–without-mysql-include=${mysql-dir}/include
–with-mysql-lib
–without-mysql-lib=${mysql-dir}/lib
–with-mysql-config
–without-mysql-config
–with-mysql-dir
–without-mysql-dir
–with-mysql-include
–without-mysql-include=${mysql-dir}/include
–with-mysql-lib
–without-mysql-lib=${mysql-dir}/lib
–with-mysqlclientlib
–without-mysqlclientlib
–with-mlib
–without-mlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-zlib
–without-zlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-socketlib
–without-socketlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-nsllib
–without-nsllib
–with-mysqlclientlib
–without-mysqlclientlib
–with-mygcclib
–without-mygcclib
–with-mysqlclientlib
–without-mysqlclientlib

extconf failed, exit code 1

Gem files will remain installed in /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/mysql2-0.3.17 for inspection.
Results logged to /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/extensions/x86-linux/2.2.0-static/mysql2-0.3.17/gem_make.out
Installing truncate_html 0.9.2
Installing spring 1.2.0
An error occurred while installing mysql2 (0.3.17), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.17'` succeeds before bundling.
[/code]

調べてたらmysql周りのものが足りないらしく
$ sudo apt-get install mysql-client libmysqlclient-dev
で解決しました

参考サイト) http://stackoverflow.com/questions/19765290/error-failed-to-build-gem-native-extension-error-installing-mysql2