はじめ
さくらのVPS
とりあえず、1G HDD50GBを選択。
カスタムOSで選べるRocky Linuxだと途中でうまくいかなかった
標準OSで「Centos8 (x86_64)」を選択して、構築後にmigrationツールでRocky Linuxに移行する。
OSが立ち上がったらrootでログインして、dnf update
migrate2rocky
$ curl -O https://raw.githubusercontent.com/rocky-linux/rocky-tools/main/migrate2rocky/migrate2rocky.sh
$ chmod 755 ./migrate2rocky.sh
$ ./migrate2rocky.sh -r
しばらくすると再起動する
作業用一般ユーザ追加
$ useradd mnguser
$ passwd mnguser
sshとfirewallの設定
$ vi /etc/ssh/sshd_config
rootの直接ログイン禁止やポートの変更などを行う
ポートを変更する場合は合わせてfirewallの設定も必要
$ dnf install firewalld
sudoの設定
一般ユーザがsudoコマンドで一時ルート権限になる設定
$ visudo
wheelの行をコメント解除
$ usermod -aG wheel mnguser
外部レポジトリ(epel & remi)の導入
$ dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
$ dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
php8のインストール
dnf update
するとremi版のphp moduleが一覧に表示される
$ dnf module php
Rocky Linux 8 - AppStream
Name Stream Profiles Summary
php 7.2 [d] common [d], devel, minimal PHP scripting language
php 7.3 common [d], devel, minimal PHP scripting language
php 7.4 common [d], devel, minimal PHP scripting language
Remi's Modular repository for Enterprise Linux 8 - x86_64
Name Stream Profiles Summary
php remi-7.2 common [d], devel, minimal PHP scripting language
php remi-7.3 common [d], devel, minimal PHP scripting language
php remi-7.4 common [d], devel, minimal PHP scripting language
php remi-8.0 common [d], devel, minimal PHP scripting language
php remi-8.1 common [d], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
構文はdnf module enable <モジュール名>:<Stream名>
既に[e]が付いている場合はdnf module reset <モジュール名>
でリセットしてからenable。
$ dnf module enable php:remi-8.0
$ dnf install php php-client php-common php-mysqlnd
この時点でのdnf module list
$ sudo dnf module list nginx
Rocky Linux 8 - AppStream
Name Stream Profiles Summary
nginx 1.14 [d][e] common [d] nginx webserver
nginx 1.16 common [d] nginx webserver
nginx 1.18 common [d] nginx webserver
Extra Packages for Enterprise Linux Modular 8 - x86_64
Name Stream Profiles Summary
nginx mainline common nginx webserver
nginx 1.20 common nginx webserver
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
$ dnf module list mariadb
Rocky Linux 8 - AppStream
Name Stream Profiles Summary
mariadb 10.3 [d] client, galera, server [d] MariaDB Module
mariadb 10.5 client, galera, server [d] MariaDB Module
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
install mariadb 10.5 and nginx 1.18.0
すでにenbaleの場合はresetする
$ dnf module reset ngninx:1.14
$ dnf module enable nginx:1.18
$ dnf install nginx
$ dnf module enable mariadb:10.5
$ dnf install mariadb
php-fpm
nginxの場合、/etc/php-fpm.d/www.conf
を変更。
userとgroupをnginxに変更
user = nginx
group = nginx
$ systemctl start php-fpm
$ systemctl enable php-fpm
ロケール設定
$ dnf install langpacks-ja
$ locatectl set-locale LANG=ja_JP.UTF-8
$ source /etc/locale.conf
Let's encrypt
EPELのcertbotではなくsnapd版のcertbotを導入
$ dnf install snapd
$ systemctl enable --now snapd.socket
$ ln -s /var/lib/snapd/snap /snap
$ snap install core
$ snap install --classic certbot
$ ln -s /snap/bin/certbot /usr/bin/certbot
nginxのSSL(Let's encrypt)化
certbot
では自サーバが簡易HTTPサーバーとして80番ポートにアクセスするのが前提となる。
一方、80番ポートはHTTPS(443番ポート)にリダイレクトさせたいので
初回は80番ポートのみのnginxの設定をしておき、certbotで証明書が取れたら
以降はリダイレクト設定を復帰させる。
簡易サーバ用のDocumentoRootを用意
$ mkdir /var/www/html/letsencrypt
$ chwon nginx:nginx /var/www/html/letsencrypt
$ chown 775 /var/www/html/letsencrypt
ドメイン「hogehoge.jp」がサーバの外部IPアドレスへのDNSの紐づけ設定はされているものとする。
$ certbot certonly --webroot -w /var/www/html/letsencrypt -d hogehoge.jp
以降開発にかかわるパッケージの導入
composer
$ wget https://getcomposer.org/installer -O composer-installer.php
$ php composer-installer.php --filename=composer --install-dir=/usr/local/bin
$ composer -V
nodejs
nodejsはnodejsで「n」というモジュールでversion管理ができる模様。
一旦dnfで標準のnodejsとnpmを入れてからnで最新版にしてdnfのモジュールは削除する。
$ dnf install nodejs
$ npm install n -g
$ n stable
$ dnf remove nodejs npm
$ exec $SHELL -l
$ npm update -g npm