centos7 nginx,php7.4,mariadb インストール

ssh鍵認証までOKである。
ドメインのネームサーバーを設定してある。


```

yum update
sudo timedatectl set-timezone Asia/Tokyo

```


epel,remiレポジトリの登録 (centos8 の場合は 7 を 8に変更)

```

sudo yum -y install epel-release
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
sudo rpm -ivh remi-release-7.rpm


```



# nginx


```/etc/yum.repos.d/nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
enabled=0
gpgcheck=0

```

```

sudo yum -y --enablerepo=nginx install nginx
nginx -v

```

//nginx version: nginx/1.17.9


# nginx 設定


```/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;
}


```


#nginx 起動

```

sudo systemctl start nginx
sudo systemctl enable nginx

```



# php

この 74 を 72 にすると php7.2 になる。


```

sudo yum --enablerepo=epel,remi,remi-php74 install php74 php74-php-mcrypt php74-php-mbstring php74-php-fpm php74-php-gd php74-php-pecl-xdebug php74-php-pecl-redis php74-php-pecl-imagick-devel php74-php-pecl-imagick php74-php-mysqlnd php74-php-intl php74-php-bcmath php74-php-pecl-zip php74-php-xmlrpc php74-php-xml  php74-php-pecl-http php74-php-pecl-http-devel php74-php-opcache

```




```

cat /opt/remi/php74/enable
export PATH=/opt/remi/php74/root/usr/bin:/opt/remi/php74/root/usr/sbin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/remi/php74/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/remi/php74/root/usr/share/man:${MANPATH}

```

vim でね。

```~/.bashrc

export PATH=/opt/remi/php74/root/usr/bin:/opt/remi/php74/root/usr/sbin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/remi/php74/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/remi/php74/root/usr/share/man:${MANPATH}


```

```

source ~/.bashrc

```



```

php -v
//PHP 7.4.4 (cli) (built: Mar 17 2020 10:40:21) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.4, Copyright (c), by Zend Technologies
    with Xdebug v2.9.4, Copyright (c) 2002-2020, by Derick Rethans

```

# php-fpm 設定

```/etc/opt/remi/php74/php-fpm.d/www.conf


user = nginx
group = nginx
listen = /var/run/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0666

```


```/etc/systemd/system/php-fpm.service

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/var/run/php-fpm.pid
ExecStart=/opt/remi/php74/root/usr/sbin/php-fpm --nodaemonize --fpm-config /etc/opt/remi/php74/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID


[Install]
WantedBy=multi-user.target

```


# php-fpm 起動


```

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

```

# ファイアウォール

```

sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload

```

#maria db

公式からサイトからリポジトリを選択する
https://downloads.mariadb.org/mariadb/repositories/



```/etc/yum.repos.d/mariadb.repo


[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

```



# インストール開始

```

sudo yum install MariaDB-server MariaDB-client MariaDB-devel 

```

# 設定

```

sudo mkdir /home/mysql
sudo chown mysql. /home/mysql

```

/etc/my.cnf.d/server.cnf

```


[mysqld]

character-set-server=utf8mb4
plugin-load = handlersocket.so
expire_logs_days = 30

[mysql]
default-character-set=utf8mb4

```


初期設定

```

mysql_secure_installation
mysql -u root -p

```

タイムゾーン設定

```

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql -p

```



ここまでで
・nginx
・php7.4
・mariadb

の設定が完了。


コーヒータイム

#さぁ、nginxで見れるかチェックしよう

```

mkdir -p /var/www/html/yamada/
vim /var/www/html/yamada/index.html

```


```/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;
}

```

# さらに。

laravel の設定
https://qiita.com/ma7ma7pipipi/items/d6c0bb5bb80713b78013

redis 4
https://qiita.com/ma7ma7pipipi/items/b6b1d940211551220cae

certbot設定
https://qiita.com/ma7ma7pipipi/items/bbadaf2d94ccec9085cd