본문 바로가기
Linux

CentOS7 + nginx 1.23 + php7.0 + php-fpm + MariaDB 10.3 설치

by 씨엔아이소프트 2023. 5. 15.
반응형

CentOS7 + nginx 1.23 + php7.0 + php-fpm + MariaDB 10.3

사전 필요 패키지 설치
yum -y install gcc gcc-c++ pcre-devel make git openssl wget vim unzip GeoIP-devel git tree cmake expat-devel libxml2-devel  openssl openssl-devel python3 curl gnupg2 libxslt-devel gd-devel perl-ExtUtils-Embed

 

1. Nginx 설치


Nginx 에서 HTTP/2 적용 과 HTTPS TLS v1.3 를 사용하기 위해서는 일정 이상의 버전이 필요합니다.

⋅ HTTP/2 : nginx 1.13.0 이상 , OpenSSL 1.0.2
⋅ HTTPS TLS v1.3 : nginx 1.9.5 , OpenSSL 1.1.1

1.1 Repository 설정


vi /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl= http://nginx.org/packages/centos/$releasever/$basearch/ 
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl= http://nginx.org/packages/mainline/centos/$releasever/$basearch/ 
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true


** mainline nginx packages 를 사용 할 것임으로 mainline repository를 활성화 하도록 하겠습니다

 

config-manager –enable nginx-mainline

 

 

1.2 기존 Nginx 삭제

yum -y remove nginx

 

1.3 기존 Nginx 설치
yum -y install nginx 

 

버전확인

nginx -V

nginx version: nginx/1.23.4


2. MariaDB 10.3 설치


YUM 저장소 추가

vi /etc/yum.repos.d/MariaDB.repo

 

** MariaDB.repo 파일 설정에 따라 버전을 달리 할 수 있습니다.

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

MariaDB 설치


yum install mariadb-server

부팅시 MariaDB 자동실행
systemctl enable mariadb

MariaDB  실행
systemctl start mariadb

패스워드 변경
mysqladmin -u root -p password

기본 설정
vi /etc/my.cnf.d/server.cnf

[mysqld] <– 절에 아래 내용을 추가로 입력해 줍니다
user=mysql
server-id=1
log_bin = binlog
expire_logs_days=10
innodb_buffer_pool_size = 384M
innodb_file_per_table=TRUE
# bind-address=0.0.0.0
character-set-client-handshake=OFF
skip-character-set-client-handshake
max_allowed_packet=500M
init_connect=SET collation_connection = utf8mb4_general_ci
init_connect=SET NAMES utf8mb4
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci


MariaDB 재시작
systemctl restart mariadb

MariaDB 초기 설정

mysql_secure_installation

 

3. PHP 설치


3.1. remi 저장소 설치
yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm


3.2. epel 저장소 설치
yum install epel-release

3.3. enable
yum-config-manager --enable remi-php70

3.4. php70 설치
yum -y install php70 php70-php-common \
php70-php-fpm php70-php-gd \
php70 php70-php-devel php70-libzip \
php70-php-mysqlnd php70-php-opcache \
php70-php-mbstring php70-php-pdo \
php70-php-pecl-imagick-devel php70-php-pecl-mcrypt \
php70-php-pecl-zip php70-php-bcmath \
curl curl-devel php70-php-pecl-imagick \
libpng libpng-devel libwebp libwebp-devel \
libXpm libXpm-devel openssl openssl-devel \
autoconf zlib zlib-devel freetype freetype-devel \
gd gd-devel libmcrypt libmcrypt-devel \
libtool-ltdl-devel libxml2-devel \
libxml2 libcurl libcurl-devel


3.5.PHP 설정

PHP 설정 파일은 /etc/php.ini 에 있으며 /etc/php.d/ 를 include 하게 되어 있으므로, 사용자 설정 파일은 /etc/php.d/php.ini 에 작성합니다.

vi /etc/php.ini
 
[PHP]

short_open_tag = Off

upload_max_filesize = 200M

post_max_size = 200M

memory_limit = 512M

date.timezone = Asia/Seoul
 
추가로 보안을 위해서 다음과 같이 추가할 수 있습니다.
 
cgi.fix_pathinfo=0
open_basedir = /home
display_errors = Off
allow_url_fopen = Off
expose_php = Off

 

4 NGINX 설정



PHP의 Runtime user:group을 설정합니다.
www.conf 파일의 user, group 부분을 찾아서 다음과 같이 변경합니다.
vi /etc/php-fpm.d/www.conf
 
user = nginx
group = nginx


vi /etc/nginx/nginx.conf
 
user    nginx nginx;

 

새로운 가상서버위한 설정
사용자추가 설정 * USER를 다른이름으로 변경하여 사용
useradd -d /home/USER USER

 

cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/USER.conf
vi /etc/nginx/conf.d/USER.conf
 
server
{
    listen 80;
     
    # 서버 이름은 IP 또는 Domain으로 작성
    server_name www.testdomain.com testdomain.com;
     
    # 웹 서버 파일 경로
    root /home/USER/www;
 
    index index.html index.htm index.php;
 
    #location ~ \.php$
    location ~ \.(php|html|htm|inc)$
    {
        #fastcgi_pass    127.0.0.1:9000;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index   index.php;
#fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include     fastcgi_params;

        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 256 16k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;

    }
}


5. PHP-FPM 설정

vi /etc/opt/remi/php70/php-fpm.conf 

;주석해제
include=/etc/opt/remi/php74/php-fpm.d/*.conf

;주석해제 
daemonize = yes

;로그레벨 기본값 notice
log_level = notice


nginx 서버에서 html 파일 안에서 php 코드 사용 가능하도록 설정
vi /etc/php-fpm.d/www.conf 
security.limit_extensions = .php .inc .html .htm

;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock

 

 

 

 

 

반응형

댓글