본문 바로가기

카테고리 없음

[CentOS 7] NGINX MYSQL PHP설치 및 연동 소스 컴파일


NGINX1.8.


MySQL 5.7.


PHP 7.0.


1. 필수 라이브러리 설치


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


2. 설치 파일 다운로드




nginx-1.8.1.tar.gz

ibmcrypt-2.5.8.tar.gz


php-7.0.0.tar.gz

mysql-5.7.12.tar.gz




3. NGINX


3-1. NGINX 컴파일



[root@~]# tar zxvf nginx-1.8.1.tar.gz

[root@~]# cd nginx-1.8.1

[root@~]# ./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_gzip_static_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 \

> --with-http_spdy_module \

> --user=nobody \

> --group=nobody

[root@~]# make && make install

[root@~]# mkdir -p /usr/local/nginx/tmp/body








3-2. NGINX 실행스크립 작성


nginx 처음 설치 후 정상적으로 실행이 안될 수 있으므로 실행파일 스크립트를 작성 합니다.


vi /etc/init.d/nginx


#!/bin/sh

#

# nginx - this script starts and stops the nginx daemin

#

# chkconfig: - 85 15

# description: Nginx is an HTTP(S) server, HTTP(S) reverse \

# proxy and IMAP/POP3 proxy server

# processname: nginx

# config: /usr/local/nginx/conf/nginx.conf

# pidfile: /var/run/nginx.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {

[ -x $nginx ] || exit 5

[ -f $NGINX_CONF_FILE ] || exit 6

echo -n $"Starting $prog: "

daemon $nginx -c $NGINX_CONF_FILE

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

stop() {

echo -n $"Stopping $prog: "

killproc $prog -QUIT

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

configtest || return $?

stop

start

}

reload() {

configtest || return $?

echo -n $"Reloading $prog: "

killproc $nginx -HUP

RETVAL=$?

echo

}

force_reload() {

restart

}

configtest() {

$nginx -t -c $NGINX_CONF_FILE

}

rh_status() {

status $prog

}

rh_status_q() {

rh_status >/dev/null 2>&1

}

case "$1" in

start)

rh_status_q && exit 0

$1

;;

stop)

rh_status_q || exit 0

$1

;;

restart|configtest)

$1

;;

reload)

rh_status_q || exit 7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q || exit 0

;;

*)

echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

exit 2

esac


3-3. NGINX 실행 및 확인



[root@~]# /etc/init.d/nginx start

nginx ()를 시작 중: [ OK ]

[root@~]# netstat -nlpt

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 14446/nginx


4. MySQL


4-1. user 및 그룹생성



[root@~]# groupadd mysql

[root@~]# useradd -g mysql mysql


4-2. cmake & boost 설치


1) mysql 5.5.x ver 이상 부터는 cmake를 이용하여 설치





[root@~]# cd /usr/local/src

[root@~]# tar zxvfp ./cmake-2.8.5.tar.gz

[root@~]# cd ./cmake-2.8.5

[root@~]#./bootstrap

[root@~]#make

[root@~]#make install

[root@~]# cd /usr/local/src

[root@~]# wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz

[root@~]# tar zxvf boost_1_59_0.tar.gz



4-3. MySQL 컴파일

 


[root@~]# cd /usr/local/src

[root@~]# tar zxvfp ./mysql-5.6.12.tar.gz

[root@~]# cd ./mysql-5.6.12

./cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \

-DMYSQL_DATADIR=/usr/local/mysql/data/ \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DSYSCONFDIR=/etc \

-DDEFAULT_CHARSET=utf8 \

-DMYSQL_TCP_PORT=3306 \

-DWITH_EXTRA_CHARSETS=all \

-DDEFAULT_COLLATION=utf8_general_ci \

-DDOWNLOAD_BOOST=1 \

-DWITH_BOOST=/usr/local/src/boost_1_59_0

[root@~]# make

[root@~]# make install


4-4. MySQL 환경 설정


1) support-files 에서 “my.cnf” 파일을 복사후 “mysql_install_db” 실행 합니다.


[root@~]# cp -arp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

[root@~]#/usr/local/src/mysql-5.7.10/client/mysql_install_db \

--user=mysql \

--basedir=/usr/local/mysql/ \

--datadir=/usr/local/mysql/data/

[root@~]# cp -arpf /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld






4-5.권한변경 및 환경변수 등록



[root@~]#chown -R mysql:mysql /usr/local/mysql/

[root@~]#chmod 700 /etc/init.d/mysqld

[root@~]#chmod 711 /usr/local/mysql

[root@~]#chmod 700 /usr/local/mysql/data

[root@~]#chmod 751 /usr/local/mysql/bin

[root@~]#chmod 750 /usr/local/mysql/bin/*

[root@~]#chmod 755 /usr/local/mysql/bin/mysql

[root@~]#chmod 755 /usr/local/mysql/bin/mysqldump

[root@~]#echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile

[root@~]#source /etc/profile


4-6. MySQL 실행 및 확인


1) mysql 실행 후 포트만 확인 하는것이 아니라 직접 접속하여 데이터베이스 생성 및 드랍 명령어


를 이용하여 테스트를 합니다.


[root@~]# /etc/init.d/mysqld start

Starting MySQL.. SUCCESS!

[root@~]# netstat -nlpt

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 14446/nginx

tcp 0 0 :::3306 :::* LISTEN 18825/mysqld

[root@~]# vi /root/.mysql_secret → mysql 5.7.ver password 확인

#안전모드 실행 후 패스워드 변경

[root@~]# /etc/init.d/mysqld stop

[root@~]# /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &

[root@~]# mysql

mysql> use mysql;

Database changed

mysql> update user set authentication_string=password('100smile@') where user='root';

Query OK, 0 rows affected (0.00 sec)

mysql> flush priviliges;

Query OK, 0 rows affected (0.00 sec)



5. PHP 설치


5-1. 라이브러리 설치


Mhash 설치

[root@~]# cd /usr/local/src

[root@~]# tar zxvf mhash-0.9.9.9.tar.gz

[root@~]# cd mhash-0.9.9.9

[root@~]#./configure

[root@~]# make && make install



[root@~]# cd /usr/local/src

[root@~]# tar zxvf libmcrypt-2.5.8.tar.gz

[root@~]# cd libmcrypt-2.5.8

[root@~]#./configure

[root@~]# make && make install






5-2. 라이브러리 링크 추가




[root@~]# ln -s /usr/local/mysql/lib/ /usr/local/mysql/lib64

[root@~]# ln -s /usr/local/lib/libmcrypt.so.4 /usr/local/lib64/libmcrypt.so.4

[root@~]# ln -sf /usr/lib64/libldap.so /usr/lib/libldap.so


5-3. PHP 컴파일





[root@~]# cd /usr/local/src

[root@~]# tar zxvf php-5.6.14.tar.gz

[root@~]# cd php-5.6.14

[root@~]# ./configure \

--prefix=/usr/local/php \

--with-config-file-path=/usr/local/php/etc \

--disable-debug \

--enable-fpm \

--enable-bcmath \

--enable-exif \

--enable-ftp \

--enable-gd-native-ttf \

--enable-inline-optimization \

--enable-intl \

--enable-mbregex \

--enable-mbstring \

--enable-mod-charset \

--enable-sigchild \

--enable-soap \

--enable-sockets \

--enable-sysvsem=yes \

--enable-sysvshm=yes \

--enable-xml \

--enable-zip \

--with-bz2 \

--with-curl \

--with-zlib \

--with-gd \

--with-gettext \

--with-mcrypt \

--with-mhash \

--with-mysql=/usr/local/mysql \

--with-mysqli \

--with-openssl \

--with-xmlrpc \

--with-freetype-dir=/usr/lib64 \

--with-jpeg-dir=/usr/lib64 \

--with-libxml-dir=/usr/lib64 \

--with-png-dir=/usr/lib64 \

--with-zlib-dir=/usr/lib64 \

--with-fpm-user=nobody \

--with-fpm-group=nobody

make

make install

[root@~]# /usr/local/php/bin/pear install PHP_Archive-0.11.4

[root@~]# cp /usr/local/src/php-5.6.14/php.ini-development /usr/local/nginx/conf/php.ini




6. NGINX PHP 연동


1) NGINX 의 경우 php-fpm이 설치 되어 있어야 연동이 가능 합니다.


Php-fpm PHP FastCGI Process Manager의 약자



[root@~]# cd /usr/local/php/etc/

[root@~]# cp -arp php-fpm.conf.default ./php-fpm.conf

[root@~]# cp -arp /usr/local/php/etc/php-fpm.d/www.conf.default www.conf

[root@~]# /usr/local/php/sbin/php-fpm → php-fpm 실행


2) nginx php-fpm이 연동 할 수 있도록 nginx.conf 파일을 수정 합니다.





[root@~]# vi /usr/local/nginx/conf/nginx.conf

#아래 내용을 주석 해제 또는 conf 파일 중간에 삽입 합니다.#


location ~ \.php$ {

root /usr/local/nginx/html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}


3) phpinfo 페이지를 확인 할 수 있도록 php파일을 html 폴더에 작성 합니다.



[root@~]#vi /usr/local/nginx/html/phpinfo.php

<?php

phpinfo();

?>



[root@~]# netstat -nlpt

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 14446/nginx

tcp 0 0 :::3306 :::* LISTEN 18825/mysqld

tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 17433/php-fpm