16.6.2.2. nginx 웹 서버와 함께 PHP 사용


nginx 웹 서버를 통해 PHP 코드를 실행할 수 있습니다. 아래 단계에서는 PHP를 사용하여 nginx 를 설치하고 구성하는 방법을 보여줍니다.

사전 요구 사항

절차

  1. nginx 모듈 스트림을 설치합니다. stream 을 설치하려는 nginx 버전으로 바꿉니다(예: 1.18):

    # yum module install nginx:stream
    # yum module install nginx:1.18
  2. nginx 서버를 시작하거나 이미 실행 중인 경우 PHP를 설치한 후 nginx 서비스를 다시 시작합니다.

    # systemctl start nginx
    # systemctl restart nginx
  3. php-fpm 서비스를 시작합니다.

    # systemctl start php-fpm
  4. 선택 사항: 부팅 시 두 서비스가 모두 시작되도록 활성화합니다.

    # systemctl enable php-fpm nginx
  5. PHP 설정에 대한 정보를 얻으려면 /usr/share/nginx/html/ 디렉터리에 다음 콘텐츠를 사용하여 index.php 파일을 생성합니다.

    # echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/index.php
  6. index.php 파일을 실행하려면 브라우저에서 다음을 가리킵니다.

    http://<hostname>/
  7. 선택 사항: 특정 요구 사항이 있는 경우 구성을 조정합니다.

    • /etc/nginx/nginx.conf - nginx 기본 구성
    • /etc/nginx/conf.d/php-fpm.conf - nginx에 대한 FPM 구성
    • /etc/php-fpm.conf - FPM 기본 설정
    • /etc/php-fpm.d/www.conf - 기본 www 풀 구성
  8. 예 - "Hello, World!" 실행 PHP 스크립트: /usr/share/nginx/html/ 디렉터리에 프로젝트의 hello 디렉터리를 생성합니다.

    # mkdir hello
  9. 다음 콘텐츠를 사용하여 /usr/share/nginx/html/hello/ 디렉터리에 hello.php 파일을 생성합니다.

    # <!DOCTYPE html>
    <html>
    <head>
    <title>Hello, World! Page</title>
    </head>
    <body>
    <?php
        echo 'Hello, World!';
    ?>
    </body>
    </html>
  10. nginx 서버를 시작합니다.

    # systemctl start nginx
  11. hello.php 파일을 실행하려면 브라우저에서 다음을 가리킵니다.

    http://<hostname>/hello/hello.php

    그 결과 "Hello, World!" 텍스트가 포함된 웹 페이지가 표시됩니다.

Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 문서 정보

Legal Notice

Theme

© 2026 Red Hat
맨 위로 이동