Help us understand the problem. What is going on with this article?

Ruby on Rails + Nginx + Unicorn + MySQL環境構築

■ アップデート
sudo yum update

■ 環境構築に必要なパッケージインストール
sudo yum install git make gcc gcc-c++ patch openssl-devel libyaml-devel libffi-devel libicu-devel libxml2 libxslt libxml2-devel libxslt-devel zlib-devel readline-devel mysql mysql-server mysql-devel ImageMagick ImageMagick-devel

■ リポジトリ追加
sudo amazon-linux-extras install epel

■ node.jsのインストール
sudo yum install nodejs npm --enablerepo=epel

■ rbenvインストール
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source .bash_profile
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv rehash

■ Rubyインストール
rbenv install -v 2.6.2
rbenv global 2.6.2
rbenv rehash
ruby -v

■ githubからソースデプロイ

■ Unicornインストール
sudo yum install mysql-devel
gem install bundler
bundle install
vim config/unicorn.conf.rb

■ config/unicorn.conf.rb生成
vim config/unicorn.conf.rb

==
$worker = 2
$timeout = 30
$app_dir = "/var/www/rails/mumu" #自分のアプリケーション名
$listen = File.expand_path 'tmp/sockets/.unicorn.sock', $app_dir
$pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir
$std_log = File.expand_path 'log/unicorn.log', $app_dir

worker_processes $worker
working_directory $app_dir
stderr_path $std_log
stdout_path $std_log
timeout $timeout
listen $listen
pid $pid
preload_app true

before_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
old_pid = "#{server.config[:pid]}.oldbin"
if old_pid != server.pid
begin
Process.kill "QUIT", File.read(old_pid).to_i
rescue Errno::ENOENT, Errno::ESRCH
end
end
end

after_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection

end

■ Nginxインストール
sudo yum install nginx
sudo vim /etc/nginx/conf.d/smallmaker.conf
sudo chmod -R 775 /var/lib/nginx

■ MySQLインストール
sudo yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm -y
sudo yum-config-manager --disable mysql80-community
sudo yum-config-manager --enable mysql57-community
sudo yum install mysql-community-server -y

SET GLOBAL validate_password_length=4;
SET GLOBAL validate_password_policy=LOW;
set password for root@localhost=password('root');

■ MySQLユーザー作成
create user smallmaker@'localhost' identified with mysql_native_password by 'smallmaker';
grant all on . to smallmaker@'localhost';

■ データベース作成
CREATE DATABASE smallmaker DEFAULT CHARSET 'utf8';

■ unicorn 起動
#unicorn_rails -c /var/project/smallmaker/application/config/unicorn.conf.rb -D -E production
unicorn -c /var/project/smallmaker/application/config/unicorn.conf.rb -D -E production

■ unicorn 停止
sudo kill -QUIT cat tmp/pids/unicorn.pid

■ nginx スタート
sudo service nginx start

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away