Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

DigitalOcean CentOS 7 서버 세팅

2015-12-19 by 편리

centos-logo-big

변덕일 것이다. 어제 우분투 서버를 세팅하고 나서 CentOS 7은 또 어떨까 싶은 생각이 들어서 무작정 DigitalOcean 의 $10 plan 을 신청하고 바로 서버 세팅을 시도해봤다. 그동안 CentOS 를 꾸준히 사용해 왔기 때문에 세팅은 그렇게 어렵지 않았다. 더구나 소스 컴파일도 아니기 때문에 문제가 생길만한 여지가 거의 없다고 해도 무방하다. 근데.. 방화벽 설정이 바뀌어서 그게 조금 시간을 잡아 먹긴 했지만 검색하니까 방법을 알 수가 있어서 무사히 서버 세팅을 마칠 수가 있었다. 설치한 서버는 nginx, mariadb, php7 이다.

타임존 변경

# mv /etc/localtime /etc/localtime_old
# cp /usr/share/zoneinfo/Asia/Seoul /etc/localtime

위와 같이 타임존을 변경해서 KST 로 표시되도록 해준다.

준비

# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
# yum install epel-release
# rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
# rpm -ivh remi-release-7.rpm
# yum install rdate
# vi /etc/yum.repos.d/MariaDB.repo

# MariaDB 10.1 CentOS repository list - created 2015-12-05 23:18 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

yum 을 이용한 설치를 위해 repository 설정을 진행했다. 부수적으로 필요한 패키지도 함께 설치를 했다.

패키지 설치

# yum install nginx
# yum install MariaDB-server MariaDB-client
# yum install php70 php70-php-fpm php70-php-gd php70-php-imap php70-php-ldap php70-php-mbstring php70-php-mcrypt php70-php-mysqlnd php70-php-opcache php70-php-pdo php70-php-dba php70-php-bcmath php70-php-soap php70-php-xml php70-php-xmlrpc

nginx 기본설정 변경

location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
}

Server 블럭의 위와 같은 Document Root 설정을 아래와 같이 변경한다.

root /usr/share/nginx/html;
index index.php index.html, index.htm;

Document Root 설정을 변경하지 않고 사용할 경우는 아래 location ~ .php$ { } 블럭 안에 root   /usr/share/nginx/html; 와 같이 PHP 파일이 있는 경로를 직접 설정해줘야 한다.

php-fpm 연동을 위한 nginx 설정

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_cache off;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_index  index.php;
    include        fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_pass   unix:/var/run/php-fpm.sock;
    include mime.types;
}

nginx 의 다른 설정을 생략하고 php-fpm 연동을 위한 설정이다. php-fpm 연동 후 php 파일이 실행되지 않고 빈 화면으로 표시되는 경우는 fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name; 설정을 추가해주면 해결되는 경우가 많다.

php-fpm pool 설정

[default]
user = nobody
group = nobody
listen = /var/run/php-fpm.sock
listen.owner = nobody
listen.group = nobody
listen.mode = 0666
;listen.allowed_clients = 127.0.0.1
;process.priority = -19
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
;pm.process_idle_timeout = 10s;
;pm.max_requests = 500
;request_terminate_timeout = 0
;rlimit_files = 1024
;rlimit_core = 0
;security.limit_extensions = .php .php3 .php4 .php5

nginx의 socket 파일과 php-fpm 의 socket 파일의 위치가 동일해야 nginx 에서 php 파일을 처리할 수 있다.

서버 데몬 시작

# systemctl start nginx.service
# systemctl start php70-php-fpm.service
# systemctl start mysql.service

service nginx start 와 같이 사용할 수도 있다.

MariaDB 기본설정

# mysqladmin -u root password 'root-passwod'
# mysql -u root -p

MariaDB [(none)]> use mysql;
MariaDB [mysql]> create user 'user'@'localhost' identified by 'user-password';

DB 서버의 root 비번을 변경하고 user 라는 사용자 아이디도 추가를 했다. user 아이디 추가는 꼭 필요한 과정은 아니며 root 비밀번호 변경은 필수 과정이다.

서버 데몬 서비스 등록

# systemctl enable nginx.service
# systemctl enable php70-php-fpm.service

서버 리부팅 때 nginx 등이 자동으로 실행되도록 하기 위해 서비스에 등록을 해줘야 한다. enable 대신 disable 을 사용하면 서비스에서 해제된다.

http(80포트) 방화벽 설정

# systemctl start firewalld.service
# firewall-cmd --state
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-port=8080/tcp
# firewall-cmd --reload
# systemctl enable firewalld.service

firewall-cmd –permanent –zone=public –add-port=8080/tcp 는 포트를 직접 지정해서 허용할 경우에 사용하는 명령어이다. 다른 포트를 사용하지 않는다면 firewall-cmd –permanent –zone=public –add-service=http 명령어만 입력하면 된다. # firewall-cmd –state 명령어를 이용해 현재 방화벽이 작동 중인지 확인할 수 있다. systemctl enable firewalld.service 는 방화벽을 부팅 때 실행되도록 서비스로 등록한다.

 

이상으로 DigitalOcean CentOS 7 서버를 구축했다.

Post navigation

Previous Post:

DigitalOcean Ubuntu 14.04 서버 세팅

Next Post:

php-fpm pool 설정

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅
  • 우분투 시스템 터미널쉘 zsh 로 변경

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes