아무거나

php7+nginx 설치 본문

PHP/PHP

php7+nginx 설치

전봉근 2019. 3. 28. 12:04
반응형

php7+nginx

1. 쉘 기본 언어값 변경(영어)  // 선택사항

   - 아무명령이나 했을때 한글 메세지가 출력되면..

   - vi /etc/default/locale

     [내용 변경]

     LANG="en_US.UTF-8"

     LANGUAGE="en"

 

2. apt-get update

 

3. apt-get upgrade

 

4. dpkg-reconfigure tzdata // 시스템 시간 설정

 

5. vi /etc/apt/sources.list   // 맨 끝줄에 저장소 추가

   [내용추가]

   # Nginx

   deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx

   deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx

 

6. 각 저장소 보안키 다운로드 후 시스템에 등록

   - 보안키 정보는 /etc/apt/trusted.gpg 에 저장된다.

 

   # Nginx

   - cd /root

   - wget http://nginx.org/keys/nginx_signing.key

   - apt-key add nginx_signing.key

   - rm nginx_signing.key

 

   # php

   - apt-get install software-properties-common

   - add-apt-repository ppa:ondrej/php

 

   - apt-key list // 추가된 보안키 목록

   - apt-get update  // APT 소스 패키지 정보 업데이트

 

7. nginx 설치

   - apt-get install nginx

   - nginx -v

 

8. php7-fpm 설치

   - apt-get install php7.0-fpm

   - php -v

   - php-fpm7.0 -v

   - apt-get install php7.0-gd php7.0-curl php7.0-mbstring

   - 그 후에 php.ini 설정 변경 ex) vi /etc/php/7.0/fpm/php.ini

     // ex) 시간, short_open_tag 설정 등..

 

9. apt-get install php7.0-mysql  // db연동관련 모듈 설치

 

10. nginx 사용자 권한 변경

    - vi /etc/nginx/nginx.conf

    - 첫줄의 user  nginx; 를 user  www-data; 로 바꾼다.

    - service nginx restart

 

11. Nginx 에서 PHP 확장자에 대해서 PHP-FPM 프로그램으로 요청을 전달하게 설정하기

    - vi /etc/nginx/conf.d/default.conf

    - 기본 값에서 주석 제거

    - 커스텀 에러페이지 구문 제거

    - vi /etc/nginx/conf.d/default.conf  // Nginx - PHP-FPM 구문 추가

    * 결과적으로 위 내용은 확인사항이고 아래 내용으로 default.conf 파일 변경

    [내용]

    server {

      listen       80;

      server_name  localhost;

      root   /usr/share/nginx/html;

 

      location / {

          index  index.php index.html;

      }

 

      location ~ [^/]\.php(/|$) {

          fastcgi_split_path_info ^(.+?\.php)(/.*)$;

          if (!-f $document_root$fastcgi_script_name) {

              return 404;

          }

 

          fastcgi_pass unix:/run/php/php7.0-fpm.sock;

          fastcgi_index index.php;

          include fastcgi_params;

      }

    }

 

    - vi /etc/nginx/fastcgi_params 도 변경

    [내용]

    fastcgi_param   QUERY_STRING            $query_string;

    fastcgi_param   REQUEST_METHOD          $request_method;

    fastcgi_param   CONTENT_TYPE            $content_type;

    fastcgi_param   CONTENT_LENGTH          $content_length;

 

    fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;

    fastcgi_param   SCRIPT_NAME             $fastcgi_script_name;

    fastcgi_param   PATH_INFO               $fastcgi_path_info;

    fastcgi_param   PATH_TRANSLATED         $document_root$fastcgi_path_info;

    fastcgi_param   REQUEST_URI             $request_uri;

    fastcgi_param   DOCUMENT_URI            $document_uri;

    fastcgi_param   DOCUMENT_ROOT           $document_root;

    fastcgi_param   SERVER_PROTOCOL         $server_protocol;

 

    fastcgi_param   GATEWAY_INTERFACE       CGI/1.1;

    fastcgi_param   SERVER_SOFTWARE         nginx/$nginx_version;

 

    fastcgi_param   REMOTE_ADDR             $remote_addr;

    fastcgi_param   REMOTE_PORT             $remote_port;

    fastcgi_param   SERVER_ADDR             $server_addr;

    fastcgi_param   SERVER_PORT             $server_port;

    fastcgi_param   SERVER_NAME             $server_name;

 

    fastcgi_param   HTTPS                   $https;

 

    # PHP only, required if PHP was built with --enable-force-cgi-redirect

    fastcgi_param   REDIRECT_STATUS         200;

 

12. 연동테스트

    - vi /usr/share/nginx/html/phpinfo.php​ 

반응형

'PHP > PHP' 카테고리의 다른 글

xdebug+webgrind 설치  (0) 2019.03.29
zend-opcache gui 설치  (0) 2019.03.29
composer 설치  (0) 2019.03.28
apache에서 index.php 죽이기  (0) 2019.03.27
json_encode 함수 옵션  (0) 2019.03.27
Comments