2021/12/17現在、 centos stream 9は snapd を インストールできないみたい。
もう少し待ってから使ったほうが良い。
まずは鍵認証までOKという前提
yum update
sudo timedatectl set-timezone Asia/Tokyo
#selinux を オフ
grubby --update-kernel ALL --args selinux=0
shutdown -r now
epel , remi を それぞれ追加
dnf config-manager --set-enabled crb
dnf install https://dl.fedoraproject.org/pub/epel/9/Everything/x86_64/Packages/e/epel-release-9-2.el9.noarch.rpm
dnf install https://dl.fedoraproject.org/pub/epel/9/Everything/x86_64/Packages/e/epel-next-release-9-2.el9.noarch.rpm
dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
dnf config-manager --set-enabled remi
#nginx の リポジトリを追加
vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
enabled=0
gpgcheck=0
#nginx インストール
yum install nginx
nginx -v
//nginx version: nginx/1.20.1 ok
#nginx の設定ファイル
vim /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
worker_rlimit_nofile 100000;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
server_tokens off;
include /etc/nginx/mime.types;
default_type text/html;
charset UTF-8;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 10;
client_header_timeout 10;
client_body_timeout 10;
reset_timedout_connection on;
send_timeout 10;
limit_conn_zone $binary_remote_addr zone=addr:5m;
limit_conn addr 100;
gzip on;
gzip_http_version 1.0;
gzip_disable "msie6";
gzip_proxied any;
gzip_min_length 1024;
gzip_comp_level 6;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/json;
open_file_cache off;
client_max_body_size 20m;
server_names_hash_bucket_size 64;
include /etc/nginx/conf.d/*.conf;
}
#php8 インストール
//まずはリスト表示
sudo dnf module list reset php -y
//8.1 を有効に
sudo dnf module enable php:remi-8.1
//php と、その他必要そうなファイルを一気にインスコ
sudo dnf install php php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imap php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml
//確認
php -v
www.conf を書き換え
vim /etc/php-fpm.d/www.conf
#user = apache
user = nginx
#group = apache
group = nginx
php-fpm再起動
sudo systemctl restart php-fpm
vim /var/www/html/yamada/index.php
<?php
phpinfo();
?>
vim /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name yourdomain.net;
root /var/www/html/yamada/;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/yamada$fastcgi_script_name;
include fastcgi_params;
}
}
sudo nginx -t
sudo systemctl restart nginx
//ついでに自動起動設定も
sudo systemctl enable nginx
sudo systemctl enable php-fpm
#firewall も開けよう
firewall-cmd --add-service=https --zone=public --permanent
firewall-cmd --add-service=http --zone=public --permanent
firewall-cmd --reload
これでサーバーのIPアドレスにアクセスして、phpinfoが表示されればOK!