2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VPS借りてCentOS7でRails本番環境を構築するまでのメモ Passenger + MySQL + Rails

Last updated at Posted at 2017-04-15

Railsで本番環境を構築したときの手順をまとめました。
毎回やってるので面倒なのでもうここにメモします。

SSHポート変更

vi /ssh/sshd_config

SELinux

最初から止まってた

firewall設定

firewall-cmd --add-port=[変えたポート]/tcp --zone=public --permanent
firewall-cmd --add-port=80/tcp --zone=public --permanent

OS日本語化

yum -y install ibus-kkc vlgothic-*
localectl set-locale LANG=ja_JP.UTF-8
source /etc/locale.conf 

Apacheとかいろいろインストール

sudo yum install -y httpd git zipopenssl-devel readline-devel zlib-devel

MySQLインストール

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update

sudo yum -y install mysql-server mysql-community-devel
sudo systemctl start mysqld
mysql -u root
	update mysql.user set password=password('[パスワード]') where user = 'root';
	flush privileges;
	exit;
create database [データベース名];

SQLite3のインストール

yum install -y sqlite sqlite-devel

Ruby インストール

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
~/.rbenv/bin/rbenv init
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
type rbenv

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv install 2.3.0
rbenv global 2.3.0

Rails インストール

gem install rails --version="4.2.5"
rbenv rehash

Passengerインストール

yum -y install libcurl-devel httpd-devel apr-devel apr-util-devel
gem install passenger

passenger-install-apache2-module
sudo chmod o+x "/root"

Apacheに以下の設定をいれる

LoadModule passenger_module /root/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/passenger-5.1.2/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
	PassengerRoot /root/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/passenger-5.1.2
	PassengerDefaultRuby /root/.rbenv/versions/2.3.0/bin/ruby
</IfModule>

<VirtualHost *:80>
  DocumentRoot /var/www/html/

  RailsEnv production
  PassengerEnabled on

  <Directory /var/www/html/>
     AllowOverride all
     Options -MultiViews
  </Directory>

</VirtualHost>

アプリインストール

git clone [gitのURL]
bundle install
bundle update rails
bundle update rake

DB初期化

bundle exec rake db:migrate RAILS_ENV=production

mkdir /var/www/html/tmp
chmod 777 /var/www/html/tmp
chmod 777 -R /var/www/html/public
2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?