LoginSignup
5
6

More than 5 years have passed since last update.

VagrantfileにPostgresqlインストール追記。

Last updated at Posted at 2015-06-08

よく使わせていただいている素敵なscotchというVagrantBoxにPostgresqlを入れるシェルを追記。

Vagrantfile
Vagrant.configure("2") do |config|

  config.vm.box = "scotch/box"
  config.vm.network "private_network", ip: "192.168.11.11"
  config.vm.hostname = 'testsite.dev'
  config.vm.synced_folder 'www', "/var/www", :mount_options => ["dmode=777", "fmode=666"]
  config.vm.provision "shell", inline: <<-EOT
        # postgresqlのVer9.4を入れる準備
        echo deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main > /etc/apt/sources.list.d/pgdg.list
        apt-get install wget ca-certificates
        wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
        apt-get update
        apt-get upgrade
        # インストール
        apt-get -yV install postgresql-9.4 postgresql-common postgresql-client-common php5-pgsql expect
        # linuxのpostgresユーザーにパスワード付与
        expect -c "
        spawn passwd postgres
        expect Enter\ ;  send pass\n;
        expect Retype\ ; send pass\n;
        expect eof exit 0
        "
        # linuxのpostgresでdbのpstgresのパスワード付与
        sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'pass';"
        # ローカルのMacから繋がるようにする
        echo "listen_addresses = '192.168.11.11'" >> /etc/postgresql/9.4/main/postgresql.conf
        echo "host postgres postgres 0.0.0.0/0 trust" >> /etc/postgresql/9.4/main/pg_hba.conf
        # 再起動
        /etc/init.d/postgresql restart
        /etc/init.d/apache2 restart
  EOT
end

Postgresql入りのBoxを探してもいい感じのなかったのでシェル使いました。
Herokuが本番なら開発もPostgresqlで行きたいですよね。

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6