16.6.2.2. nginx 웹 서버와 함께 PHP 사용
nginx 웹 서버를 통해 PHP 코드를 실행할 수 있습니다. 아래 단계에서는 PHP를 사용하여 nginx 를 설치하고 구성하는 방법을 보여줍니다.
사전 요구 사항
PHP 스크립팅 언어가 시스템에 설치되어 있습니다.
PHP 스크립팅 언어 설치를 참조하십시오.
절차
nginx모듈 스트림을 설치합니다. stream 을 설치하려는nginx버전으로 바꿉니다(예: 1.18):# yum module install nginx:stream# yum module install nginx:1.18nginx서버를 시작하거나 이미 실행 중인 경우 PHP를 설치한 후nginx서비스를 다시 시작합니다.# systemctl start nginx# systemctl restart nginxphp-fpm서비스를 시작합니다.# systemctl start php-fpm선택 사항: 부팅 시 두 서비스가 모두 시작되도록 활성화합니다.
# systemctl enable php-fpm nginxPHP 설정에 대한 정보를 얻으려면
/usr/share/nginx/html/디렉터리에 다음 콘텐츠를 사용하여index.php파일을 생성합니다.# echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/index.phpindex.php파일을 실행하려면 브라우저에서 다음을 가리킵니다.http://<hostname>/선택 사항: 특정 요구 사항이 있는 경우 구성을 조정합니다.
-
/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풀 구성
-
예 - "Hello, World!" 실행 PHP 스크립트:
/usr/share/nginx/html/디렉터리에 프로젝트의hello디렉터리를 생성합니다.# mkdir hello다음 콘텐츠를 사용하여
/usr/share/nginx/html/hello/디렉터리에hello.php파일을 생성합니다.# <!DOCTYPE html> <html> <head> <title>Hello, World! Page</title> </head> <body> <?php echo 'Hello, World!'; ?> </body> </html>nginx서버를 시작합니다.# systemctl start nginxhello.php파일을 실행하려면 브라우저에서 다음을 가리킵니다.http://<hostname>/hello/hello.php그 결과 "Hello, World!" 텍스트가 포함된 웹 페이지가 표시됩니다.