LoginSignup
1
2

More than 5 years have passed since last update.

GCE + CloudSQL に Railsアプリをデプロイする方法

Last updated at Posted at 2018-09-05

GCP GCE CentOS6

CentOS6の初期設定


$ yum update -y
$ yum install -y epel-release
$ yum install -y gcc gcc-c++ make
$ yum install -y git tig zlib-devel libxml2-devel libxslt-devel readline-devel openssl-devel ImageMagick ImageMagick-devel
$ yum install -y curl-devel bind-utils sqlite sqlite-devel bzip2 which
$ yum install -y httpd httpd-devel curl-devel bind-utils
$ yum install -y mysql-devel
$ yum install -y nodejs --enablerepo=epel

# selinux無効化
$ setenforce 0

Rubyインストール


$ echo 'gem: --no-ri --no-rdoc' >> ~/.gemrc
$ mkdir -v /usr/local/rbenv
$ groupadd rbenv
$ chgrp -R rbenv /usr/local/rbenv
$ chmod -R g+rwxXs /usr/local/rbenv
$ git clone https://github.com/sstephenson/rbenv.git /usr/local/rbenv
$ git clone https://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugins/ruby-build

$ vi .bash_profile
export RBENV_ROOT=/usr/local/rbenv
export PATH=${RBENV_ROOT}/shims:${RBENV_ROOT}/bin:${PATH}

$ source .bash_profile
$ rbenv install 2.4.2
$ rbenv global 2.4.2

Webサーバ準備(apache+passenger)


$ gem install rails
$ gem install passenger
$ passenger-install-apache2-module -a
$ touch /etc/httpd/conf.d/passenger.conf
$ passenger-install-apache2-module --snippet >> /etc/httpd/conf.d/passenger.conf

アプリケーション設置


$ cd /var/www/
$ git clone [リポジトリー] sample-app
$ cd sample-app/
$ bundle

confファイルの設置


$ vi /etc/httpd/conf.d/test-batch-app.conf

sample-app.conf
<VirtualHost *:80>
   ServerName localhost

   RailsEnv production
   SetEnv SECRET_KEY_BASE d96fbcea88c6d235e458218c0d123ce60008b4a1e556c

   DocumentRoot /var/www/test-batch-app/public
   <Directory /var/www/test-batch-app/public>
     AllowOverride all
     Options -MultiViews
     Allow from all
     # Uncomment this if you're on Apache > 2.4:
     # Require all granted
   </Directory>
</VirtualHost>

Cloud SQL Proxy 設定


$ cd
$ wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
$ chmod +x cloud_sql_proxy
$ mkdir /cloudsql
$ chmod 777 /cloudsql/

# プロキシースタート
$ ./cloud_sql_proxy -instances="[YOUR_INSTANCE_CONNECTION_NAME]" -dir=/cloudsql

参考

1
2
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
1
2