[Rocky] 15. WEB(Nginx) + WAS(PHP) + DB(MariaDB)
카테고리: ROCKY
01) WEB 구성요소

| 구성요소 | 설명 |
|---|---|
| WEB 서버 | 정적인 컨텐츠(문자, 그림, 오디오, 비디오 등)를 처리하는 서버 |
| WAS 서버 | 동적인 컨텐츠(사용자의 입력 값을 기반으로 프로그램의 동작이 달라 짐)를 처리하는 서버 |
| DB 서버 | 데이터베이스를 생성, 관리, 사용, 제어하는 서버 |
02) 서버 정보
03) 서버 구성
a) WEB Server - Apache install and configuration
# /etc/hosts에 서버 IP 주소 정보 추가
$ cat <<EOF >> /etc/hosts
192.168.219.100 web
192.168.219.111 was01
192.168.219.200 db
EOF
# Nginx 설치
$ yum install -y nginx
# /etc/nginx/nginx.conf 파일에서 아래와 같이 추가
$ vim /etc/nginx/nginx.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# 추가해야할 부분
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass was01:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
# 서비스를 활성화하고 시작(start)하도록 지정
$ systemctl enable --now nginx
# 방화벽 허용
$ firewall-cmd --add-service=http
$ firewall-cmd --add-port=9000/tcp
$ firewall-cmd --runtime-to-permanent
# Apache가 네트워크 연결을 수행할 수 있도록 허용
$ setsebool -P httpd_can_network_connect on
b) WAS Server - PHP-FPM install and configuration
# /etc/hosts에 서버 IP 주소 정보 추가
$ cat <<EOF >> /etc/hosts
192.168.219.100 web
192.168.219.111 was01
192.168.219.200 db
EOF
# PHP 설치
$ dnf module list php
CentOS Stream 9 - AppStream
Name Stream Profiles Summary
php 8.1 common [d], devel, minimal PHP scripting language
$ dnf module reset php
$ dnf module -y enable php:8.1
$ dnf module -y install php:8.1/common; dnf -y install php-mysqlnd
# /etc/php-fpm.d/www.conf 파일에서 아래 내용 추가
$ vim /etc/php-fpm.d/www.conf
listen = 9000
listen.allowed_clients = 192.168.219.100
# 서비스를 활성화하고 시작(start)하도록 지정
$ systemctl enable --now php-fpm
# 방화벽 허용
$ firewall-cmd --add-service=http
$ firewall-cmd --add-port=9000/tcp
$ firewall-cmd --add-port=3306/tcp
$ firewall-cmd --runtime-to-permanent
# Apache가 SELinux를 통해 원격 데이터베이스에 연결하도록 허용
$ setsebool -P httpd_can_network_connect_db 1
# 테스트 php 파일 생성
$ mkdir -p /usr/share/nginx/html
$ cat <<EOF >> /usr/share/nginx/html/info.php
<?php phpinfo(); ?>
EOF
c) DB Server - MariaDB Install
# MariaDB 설치
$ yum -y install mariadb-server mariadb
# 서비스를 활성화하고 시작(start)하도록 지정
$ systemctl enable --now mariadb
# 방화벽 허용
$ firewall-cmd --add-port=3306/tcp
# MariaDB 설정
$ mysql_secure_installation
# test 용 DB 생성
$ mysql -u root -p
$ create database test;
# 외부 접근 허용
$ GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'PASSWORD';
$ exit;
d) WAS Server - DB connection check
# DB 연결 체크용 php 파일 작성
$ cat <<EOF >> /usr/share/nginx/html/dbtest.php
WAS01
<?php
\$host = '192.168.219.200';
\$user = 'root';
\$pw = '1234';
\$dbName = 'test';
\$mysqli = new mysqli(\$host, \$user, \$pw, \$dbName);
if(\$mysqli){
echo "MySQL 접속 성공";
}else{
echo "MySQL 접속 실패";
}
?>
EOF
댓글 남기기