CentOS 7 + MariaDB + NginX + PHP 설치 (컴파일방식)




YUM을 이용한 설치가 편하지만, 솔루션의 설치 위치 지정을 위해 매뉴얼(컴파일) 설치를 아래와 같이 해봤습니다.



설치환경

■ OS Version

CentOS 7 (Linux 3.10.0-514.26.2.el7.x86_64)


■ 솔루션 Version

MariaDB Version : mariadb-10.2.7

NginX Version : nginx-1.9.9

PHP Version : php-7.1.7


■ 경로

솔루션 다운로드 위치: /usr/local/src

솔루션 설치 위치: /usr/local/각솔루션명



필수라이브러리 설치

# yum -y install gcc* make libtool-ltdl-devel openssl-devel pcre-devel ncurses-devel libxml2-devel bzip2-devel curl-devel gdbm-devel libjpeg-devel libpng-devel freetype-devel imap-devel libc-client-devel krb5-devel libmcrypt libmcrypt-devel libmhash-devel flex icu libicu libicu-devel gd gd-devel wget gzip libxslt-devel cmake ncurses ncurses-devel bison gnutls-devel



MariaDB , NginX , PHP 다운로드 하기와 압축풀기

# cd /usr/local/src
# wget http://nginx.org/download/nginx-1.9.9.tar.gz
# wget http://mirror.cogentco.com/pub/php/php-7.1.7.tar.gz
# wget https://downloads.mariadb.org/interstitial/mariadb-10.2.7/source/mariadb-10.2.7.tar.gz

# tar xzf nginx-1.9.9.tar.gz
# tar xzf php-7.1.7.tar.gz
# tar xzf mariadb-10.2.7.tar.gz



NginX 설치

# useradd --shell /sbin/nologin nginx
# cd /usr/local/src/nginx-1.9.9
# ./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --sbin-path=/usr/local/nginx/sbin/nginx --lock-path=/usr/local/nginx/nginx.lock --pid-path=/usr/local/nginx/nginx.pid --http-client-body-temp-path=/usr/local/nginx/tmp/body --http-proxy-temp-path=/usr/local/nginx/tmp/proxy --http-fastcgi-temp-path=/usr/local/nginx/tmp/fastcgi --http-uwsgi-temp-path=/usr/local/nginx/tmp/uwsgi --http-scgi-temp-path=/usr/local/nginx/tmp/scgi --http-log-path=/usr/local/nginx/logs/access.log --error-log-path=/usr/local/nginx/logs/error.log --with-http_addition_module --with-http_degradation_module --with-http_flv_module  --with-http_image_filter_module --with-http_mp4_module --with-http_random_index_module  --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_realip_module --with-http_xslt_module --with-http_dav_module --with-http_auth_request_module --user=nginx --group=nginx

# make & make install



NginX 기동 스크립트 작성과 기타작업

※ nginx 소스에는 시작,중지 등의 스크립트가 없다. CentOS용 스크립트를 가져다 쓰자. (스크립트 다운로드 받기)
다른 OS 참고: https://www.nginx.com/resources/wiki/start/topics/examples/initscripts/

# vi /etc/rc.d/init.d/nginx <-- 다운받은 파일내용을 붙여넣기 한다.
# chmod +x /etc/init.d/nginx
# chkconfig --add nginx

# chown -R nobody:nobody /usr/local/nginx/tmp



방화벽에 http,https 서비스 오픈

# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload



MariaDB 설치

# groupadd -g 27 -o -r mysql
# useradd -M -g mysql -o -r -d /usr/local/mariadb/data -s /bin/false -c “MariaDB” -u 27 mysql

# mkdir /usr/local/mariadb
# mkdir /usr/local/mariadb/logs
# mkdir /usr/local/mariadb/tmp
# chown -R mysql.mysql /usr/local/mariadb
# cd BUILD

# cmake .. -DWITH_READLINE=1 -DWITH_SSL=bundled -DWITH_ZLIB=system -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=all -DWITH_ARIA_STORAGE_ENGINE=1 -DWITH_XTRADB_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATEDX_STORAGE_ENGINE=1-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb -DMYSQL_DATADIR=/usr/local/mariadb/data

# make && make install

# cp /usr/local/mariadb/support-files/my-medium.cnf /etc/my.cnf

# /usr/local/mariadb/scripts/mysql_install_db --basedir=/usr/local/mariadb --datadir=/usr/local/mariadb/data
# chown -R mysql.mysql /usr/local/mariadb/data

# cp /usr/local/mariadb/support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --list | grep mysqld



MaraDB 관리자 암호 변경

# /etc/rc.d/init.d/mysqld start
Starting mysqld (via systemctl):                           [  OK  ]
# /etc/rc.d/init.d/mysqld start
# /usr/local/mariadb/bin/mysqladmin -u root password 암호지정



PHP 설치

# cd /usr/local/src/php-7.1.7
# ./configure --prefix=/usr/local/php-7.1 --with-config-file-path=/etc/php71 --with-config-file-scan-dir=/etc/php71/php.d --with-zlib-dir --enable-mbstring --with-curl --with-mcrypt --with-zlib --disable-rpath --enable-inline-optimization --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-mysqli --with-openssl --with-fpm-user=nobody --with-fpm-group=nobody --enable-fpm --with-pdo-mysql

# make && make install



PHP-fpm 설정

# mkdir /etc/php71
# cp /usr/local/src/php-7.1.7/php.ini-production /etc/php71/php.ini
# cp /usr/local/php-7.1/etc/php-fpm.conf.default /usr/local/php-7.1/etc/php-fpm.conf
# cp /usr/local/php-7.1/etc/php-fpm.d/www.conf.default /usr/local/php-7.1/etc/php-fpm.d/www.conf

# cp /usr/local/src/php-7.1.7/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm

# chkconfig php-fpm on

# vi /usr/local/php-7.1/etc/php-fpm.d/www.conf 아래 문구를 바꿈 혹은 수정

;listen = 127.0.0.1:9000 ;주석처리 listen = /tmp/php7-fpm.sock listen.owner = nginx listen.group = nginx listen.mode = 0660



NginX에 PHP 설정

# vi /usr/local/nginx/conf/nginx.conf

server {
        listen       80;
        server_name  도메인;

        server_tokens off;
        
        location / {
            root   /usr/local/www;
            index  index.html index.htm;
        }

        location ~ \.php$ {
            root           /usr/local/www;
            try_files $uri =404;
            fastcgi_pass unix:/tmp/php7-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        } 
    }



방화벽 및 SE 설정

# setsebool -P httpd_can_network_connect=1
# setsebool -P httpd_can_network_connect_db=1
# setsebool -P httpd_can_network_relay=1
# setsebool -P user_tcp_server=1

# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload



MYSQL, PHP, NginX 서버 기동

# service mysqld start
# service php-fpm start
# service nginx start



서버 확인

# vi /usr/local/www/info.php
아래 입력
 
<?php phpinfo(); ?>

브라우저에서 http://도메인주소/info.php 로 아래와 같이 php info정보가 표시되면 잘 설치 된 것이다.




확인하고 위에서 만든 파일은 보안을 위해 삭제한다 (rm -f /usr/local/www/info.php)





설치 끝.



Comments 0