環境
Ubuntu20.04 LTS
git version 2.25.1
MySQL version 8.0.23
rbenvのインストール
terminal
$ sudo apt update
$ sudo apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ ~/.rbenv/bin/rbenv init
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ source ~/.bashrc
$ rbenv -v #インストールできたか確認
ruby-buildのインストール
terminal
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
Rubyのインストール
terminal
$ rbenv install 2.7.2 #今回は2.7.2を入れました
$ rbenv global 2.7.2 #デフォルトを2.7.2に
$ ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
Nginxのインストール
terminal
sudo apt-get install nginx
Passengerパッケージのインストール
Passenger公式はこちら
terminal
$ sudo apt-get install -y dirmngr gnupg
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
$ sudo apt-get install -y apt-transport-https ca-certificates
$ sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger focal main > /etc/apt/sources.list.d/passenger.list'
$ sudo apt-get update
$ sudo apt-get install -y libnginx-mod-http-passenger
Passenger Nginx モジュールの有効化
terminal
$ if [ ! -f /etc/nginx/modules-enabled/50-mod-http-passenger.conf ]; then sudo ln -s /usr/share/nginx/modules-available/mod-http-passenger.load /etc/nginx/modules-enabled/50-mod-http-passenger.conf ; fi
$ sudo ls /etc/nginx/conf.d/mod-http-passenger.conf
Nginx再起動
terminal
$ sudo service nginx restart
インストールをチェック
terminal
$ sudo /usr/bin/passenger-config validate-install
Use <space> to select.
If the menu doesn't display correctly, press '!'
‣ ⬢ Passenger itself #ここでenter
⬡ Apache
-------------------------------------------------------------------------
* Checking whether this Passenger install is in PATH... ✓
* Checking whether there are no other Passenger installations... ✓
Everything looks good. :-) #これが表示されればOK
もし上記のようにいかない場合、画面の指示に従う
NginxがPaseengerプロセスを開始したことをチェック
terminal
$ sudo /usr/sbin/passenger-memory-stats #下記みたいなのが出ればOK
Version: 5.0.8
Date : 2015-05-28 08:46:20 +0200
...
---------- Nginx processes ----------
PID PPID VMSize Private Name
-------------------------------------
12443 4814 60.8 MB 0.2 MB nginx: master process /usr/sbin/nginx
12538 12443 64.9 MB 5.0 MB nginx: worker process
### Processes: 3
### Total private dirty RSS: 5.56 MB
----- Passenger processes ------
PID VMSize Private Name
--------------------------------
12517 83.2 MB 0.6 MB PassengerAgent watchdog
12520 266.0 MB 3.4 MB PassengerAgent server
12531 149.5 MB 1.4 MB PassengerAgent logger
...
パッケージ更新
terminal
$ sudo apt-get update
$ sudo apt-get upgrade
# nginxまたはPassengerを再起動する必要はなし
git clone
terminal
# 適当なディレクトリで
$ git clone https:// ... myapp.git
PassengerとRailsアプリケーションの連携
terminal
$ cd /etc/nginx/sites-enabled
$ touch myapp.conf
$ vi myapp.conf
server {
listen 80;
server_name myapp.jp;
access_log /var/log/nginx/myapp.jp-access.log;
error_log /var/log/nginx/myapp.jp-error.log;
root /home/username/git/myapp/public; #git cloneしたアプリの下をpublicにすればたぶん大丈夫
rails_env production;
passenger_enabled on;
index index.html;
}