Debian Wheezy에 PHP5(및 PHP-FPM) 및 MySQL 지원(LEMP)을 사용하여 Nginx 설치

Debian Wheezy에 PHP5(및 PHP-FPM) 및 MySQL 지원(LEMP)을 사용하여 Nginx 설치

2022-10-19 last update

8 minutes reading nginx web server debian
Nginx("엔진 x"로 발음)은 무료 오픈 소스 고성능 HTTP 서버입니다. Nginx는 안정성, 풍부한 기능 세트, 간단한 구성 및 낮은 리소스 소비로 유명합니다. 이 튜토리얼에서는 PHP5 지원(PHP-FPM을 통해) 및 MySQL 지원(LEMP = Linux + nginx("엔진 x"로 발음) + MySQL + PHP)을 사용하여 Debian Wheezy 서버에 Nginx를 설치하는 방법을 보여줍니다.
나는 이것이 당신에게 효과가 있다는 어떤 보장도 하지 않습니다!

1 서문


이 튜토리얼에서는 IP 주소가 192.168.0.100인 호스트 이름 server1.example.com을 사용합니다. 이러한 설정은 사용자에 따라 다를 수 있으므로 적절한 경우 교체해야 합니다.

2 MySQL 5 설치하기


MySQL을 설치하기 위해 다음을 실행합니다.
apt-get install mysql-server mysql-client
MySQL 루트 사용자의 비밀번호를 제공하라는 메시지가 표시됩니다. 이 비밀번호는 [email protected][email protected] 사용자에게 유효하므로 나중에 MySQL 루트 비밀번호를 수동으로 지정할 필요가 없습니다. :
MySQL "루트"사용자의 새 비밀번호: <-- yourrootsqlpassword MySQL "루트"사용자의 비밀번호 반복: <-- yourrootsqlpassword

3 Nginx 설치


Nginx는 다음과 같이 설치할 수 있는 Debian Wheezy용 패키지로 제공됩니다.
apt-get install nginx
나중에 nginx를 시작하십시오.
/etc/init.d/nginx start
웹 서버의 IP 주소 또는 호스트 이름을 브라우저(예: http://192.168.0.100)에 입력하면 다음 페이지가 표시됩니다.

Debian Wheezy의 기본 nginx 문서 루트는/usr/share/nginx/www입니다.

4 PHP5 설치


PHP-FPM (PHP-FPM(FastCGI Process Manager)는 모든 규모의 사이트, 특히 더 바쁜 사이트에 유용한 몇 가지 추가 기능이 있는 대체 PHP FastCGI 구현입니다)를 통해 nginx에서 PHP5를 작동하도록 할 수 있습니다. 이 구현은 다음과 같이 설치합니다.
apt-get install php5-fpm
PHP-FPM은 소켓/var/run/php5-fpm.sock에서 FastCGI 서버를 실행하는 데몬 프로세스(초기 스크립트/etc/init.d/php5-fpm 포함)입니다.

5 nginx 설정


nginx 구성은/etc/nginx/nginx.conf에 있으며 지금 열려 있습니다.
vi /etc/nginx/nginx.conf
구성은 이해하기 쉽습니다(여기에서 자세한 내용을 알아볼 수 있습니다: http://wiki.nginx.org/NginxFullExample 및 여기: http://wiki.nginx.org/NginxFullExample2 ).
먼저(선택 사항) 작업자 프로세스 수를 조정하고 keepalive_timeout을 적절한 값으로 설정합니다.


[...]
worker_processes  4;
[...]
    keepalive_timeout   2;
[...]

가상 호스트는 서버 {} 컨테이너에 정의됩니다. 기본 가상 호스트는/etc/nginx/sites-available/default 파일에 정의되어 있습니다. 다음과 같이 수정해 보겠습니다.
vi /etc/nginx/sites-available/default


[...]
server {
        listen   80; ## listen for ipv4; this line is default and implied
        listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

        root /usr/share/nginx/www;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                allow ::1;
                deny all;
        }

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #       proxy_pass http://127.0.0.1:8080;
        #}

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/www;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

                # With php5-cgi alone:
                #fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}
[...]

두 수신 라인의 주석 처리를 제거하여 nginx가 포트 80 IPv4 및 IPv6에서 수신하도록 합니다.
서버 이름 _; 이것을 기본 catchall 가상 호스트로 만듭니다(물론 www.example.com과 같이 여기에서 호스트 이름을 지정할 수도 있습니다).
index.php를 인덱스 라인에 추가했습니다. 루트/usr/share/nginx/www; 문서 루트가/usr/share/nginx/www 디렉토리임을 의미합니다.
PHP에서 중요한 부분은 위치 ~\.php$ {} 스탠자입니다. 활성화하려면 주석 처리를 제거하십시오. try_files $uri =404; 제로 데이 익스플로잇을 방지하기 위해(http://wiki.nginx.org/Pitfalls#Passing_Uncontrolled_Requests_to_PHPhttp://forum.nginx.org/read.php?2,88845,page=3 참조).
이제 파일을 저장하고 nginx를 다시 로드합니다.
/etc/init.d/nginx reload
다음으로/etc/php5/fpm/php.ini를 엽니다...
vi /etc/php5/fpm/php.ini
... cgi.fix_pathinfo=0을 설정합니다.


[...]
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0
[...]

PHP-FPM 다시 로드:
/etc/init.d/php5-fpm reload
이제 문서 루트/usr/share/nginx/www에 다음 PHP 파일을 만듭니다.
vi /usr/share/nginx/www/info.php


<?php
phpinfo();
?>

이제 브라우저에서 해당 파일을 호출합니다(예: http://192.168.0.100/info.php).

보시다시피 PHP5는 작동 중이며 Server API 라인에서 볼 수 있듯이 FPM/FastCGI를 통해 작동합니다. 더 아래로 스크롤하면 PHP5에서 이미 활성화된 모든 모듈을 볼 수 있습니다. MySQL은 거기에 나열되어 있지 않습니다. 이는 PHP5에서 아직 MySQL을 지원하지 않는다는 것을 의미합니다.