[忘備録]開発環境の仮想マシンにCentOS7をインストールしてやること

###dnfのインストール

```terminal
# yum install wget epel-release
# yum install dnf
```

###アップデート

```terminal
# dnf update
# systemctl reboot -i
```

###vimのインストール
```terminal
# dnf install vim
```

###unzipのインストール
```terminal
# dnf install unzip
```

###Apacheのインストール
```terminal
# dnf install https://centos7.iuscommunity.org/ius-release.rpm
# dnf install --enablerepo=ius httpd24u httpd24u-devel httpd24u-mod_ssl
# dnf install --enablerepo=epel nghttp2

# systemctl enable httpd
# systemctl start httpd
```

```diff:/etc/httpd/conf.d/ssl.conf
<VirtualHost _default_:443>
+<IfModule http2_module>
+  ProtocolsHonorOrder On
+  Protocols h2 http/1.1
+</IfModule>
```

```diff:/etc/httpd/conf.modules.d/00-mpm.conf
-LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
+#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
-#LoadModule mpm_event_module modules/mod_mpm_event.so
+LoadModule mpm_event_module modules/mod_mpm_event.so 
```

```terminal
# systemctl restart httpd
```

その他：[参考](https://blog.apar.jp/linux/8426/)

###PHPのインストール

```terminal
# dnf install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# dnf install --enablerepo=remi-php73 php php-mysqli php-mbstring php-pear php-pecl-zip php-fpm

# systemctl enable php-fpm
# systemctl start php-fpm
```

###MariaDBのインストール

```conf:/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
```

```terminal
# dnf install mariadb mariadb-server

systemctl enable mariadb
systemctl start mariadb

# mysql_secure_installation

# setsebool -P httpd_can_network_connect=1
```

###phpMyAdminのインストール
```terminal
# cd /var/www/html/
# wget https://files.phpmyadmin.net/phpMyAdmin/4.8.4/phpMyAdmin-4.8.4-all-languages.zip
# unzip phpMyAdmin-4.8.4-all-languages.zip
# phpMyAdmin-4.8.4-all-languages mysqlad
```

###firewallの設定

```terminal
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload
```
###動作確認

```
https://server_id_addr/mysqlad/
でphpMyAdminの接続とhttp/2.0の有効化をHTTP/2 Indicatorにて確認
```
[HTTP/2 Indicator](https://addons.mozilla.org/ja/firefox/addon/http2-indicator/)
[HTTP/2 and SPDY indicator](https://chrome.google.com/webstore/detail/http2-and-spdy-indicator/mpbpobfflnpcgagjijhmgnchggcjblin?hl=ja)


LAMPの設定はここまで


###semanageのインストール

```terminal
#dnf install policycoreutils-python
```

###Apacheで利用可能なselinuxコンテキスト登録済なポートを確認

```terminal
#semanage port -l | grep http
http_cache_port_t              tcp      8080, 8118, 8123, 10001-10010
http_cache_port_t              udp      3130
http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t            tcp      5988
pegasus_https_port_t           tcp      5989
```

###Apacheの使用ポートを変更

```diff:/etc/httpd/conf/httpd.conf
-Listen 80
+Listen 81
```

```diff:/etc/httpd/conf.d/ssl.conf
-Listen 443 https
+Listen 8443 https

-<VirtualHost _default_:443>
+<VirtualHost _default_:8443>
```
###Nginxのインストール
```/etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1
```

```terminal
# dnf install nginx
# systemctl enable nginx
# systemctl start nginx

# mkdir -p /etc/pki/nginx/private/
# cp /etc/pki/tls/certs/localhost.crt /etc/pki/nginx/localhost.crt
# cp /etc/pki/tls/private/localhost.key /etc/pki/nginx/private/localhost.key
```

```diff:/etc/nginx/conf.d/ssl.conf
server {
    listen       443 ssl http2 default_server;
    listen       [::]:443 ssl http2 default_server;
    server_name  _;
    root         /usr/share/nginx/html;
    index index.html index.htm index.php;

    ssl_certificate "/etc/pki/nginx/localhost.crt";
    ssl_certificate_key "/etc/pki/nginx/private/localhost.key";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php {
         fastcgi_pass  127.0.0.1:9000;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include       fastcgi_params;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}
```

###Node.jsのインストール

```terminal
# dnf install --enablerepo=epel npm
# npm install -g n
# n latest
# npm install -g yarn
```