본문 바로가기
SW/APM

NGINX + PHP 컴파일 소스 설치

by bigju 2021. 9. 28.

설치 환경 : Centos 7.3 VMware

1. NGINX 설치

# 필요한 라이브러리 설치

 

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 yum -y install epel-release yum -y install php-mcrypt yum -y install libmcrypt-devel

 

 

 

# 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

 

# NGINX 설치

 

tar -xfz nginx-1.9.9.tar.gz cd /usr/local/src/nginx-1.9.9

 

# nginx 컴파일

 

 

./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 기동 스크립터 작성

 

useradd --shell /sbin/nologin nginx 

vi /etc/init.d/nginx <---- 이곳에 스크립터 작성 // 내용은 밑

chmod +x /etc/init.d/nginx 

chkconfig --add nginx

chkconfig nginx on 

mkdir /usr/local/nginx/tmp

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

 

!!스크립터 작성 내용

 

# !/bin/sh 
# Author:Ryan Norbauer http://norbauerinc.com 
# Modified : Geoffrey Grosenbach http://topfunky.comtar cfz 
# Modified : Clment NEDELCU 
# Reproduced with express authorization from its contributors 
# chkconfig: 345 85 15 

set -e 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 
DESC="nginx daemon" 
NAME=nginx 
DAEMON=/usr/local/nginx/sbin/$NAME 

# if daemon file not exist, script stop 
test -x $DAEMON || exit 0 

d_start() { 
$DAEMON || echo -n "already running" 
} 

d_stop() { 
$DAEMON -s quit || echo -n "not running" 
} 

d_reload() { 
$DAEMON -s reload || echo -n "could not reload" 
} 

case "$1" in 

start) 
echo -n "Starting $DESC : $NAME" 
d_start echo "." ;; stop) 
echo -n "Stopping $DESC : $NAME" d_stop echo "." 
;; 

reload) echo -n "Reloading $DESC configuration..." 
d_reload 
echo "reloaded." ;; 

restart) 
echo -n "Restarting $Desc : $NAME" 
d_stop 
sleep 2 
d_start 
echo "." 
;; 

*) 
echo "Usage : $SCRIPTNAME {start|stop|restart|reload}" >&2 
exit 3 

ll 

esac 
exit 0

 

# 설치 확인

 

service nginx start http://ip

2. PHP설치

cd /usr/local/src/ 

tar xfz php-7.1.7.tar.gz cd php-7.1.7





# 컴파일

./configure \ 
--prefix=/usr/local/php \ 
--with-config-file-path=/etc/php \ 
--with-config-file-scan-dir=/etc/php/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 test 

make install

3. php-fpm 설정

mkdir /etc/php71 

cp /usr/local/src/php-7.1.7/php.ini-production /etc/php71/php.ini 

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf 

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/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
 
 chkconfig php-fpm on

 

 

# conf 파일 수정

 

vi /usr/local/php/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

 

 

4. 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; 
 /scripts$fastcgi_script_name; 
 		include fastcgi_params; 
        
        } 
        
  } 
  
  * 여기서 연동이 안된다하면 이 페이지에 있는 root 경로가 전부 다 같은지 확인할것

# 방화벽 설정

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

# 서비스 시작

 

service php-fpm start service nginx start

# 확인

 

vi /usr/local/www/info.php

<?
php phpinfo(); 
?> 


http:// ip /info.php

 

# php 옵션 창

​BigJu

댓글

메인으로가기


    

Big Ju

IT Engineer


항상 답을 위해 노력하는

엔지니어입니다.

 

 

    


 UP!