본문 바로가기

리눅스

우분투 24.04에서 Nginx 1.28과 PHP 8.3을 설치하는 방법

반응형

우분투 24.04에서 Nginx 1.28과 PHP 8.3을 설치하는 방법

테스트 환경

$ lsb_release -d
Description:    Ubuntu 24.04.1 LTS

Nginx 설치

필수 구성 요소 설치

sudo apt update
sudo apt install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring

Nginx 저장소 추가

curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

Nginx 설치

sudo apt update
sudo apt install -y nginx

Nginx 버전 확인

nginx -v
nginx version: nginx/1.28.0

Nginx 서비스 시작 및 활성화

sudo systemctl enable --now nginx
728x90

PHP 설치

필수 구성 요소 설치

sudo apt install -y software-properties-common apt-transport-https

PHP PPA 추가

sudo add-apt-repository -y ppa:ondrej/php

패키지 목록 업데이트

sudo apt-get update

PHP 8.3 및 관련 모듈 설치

sudo apt-get install -y php8.3 php8.3-fpm php8.3-cli php8.3-common \
  php8.3-mysql php8.3-zip php8.3-gd php8.3-mbstring php8.3-curl php8.3-xml \
  php8.3-bcmath php8.3-xmlrpc php8.3-dev php8.3-intl
sudo apt-get install -y php8.3-redis php8.3-mongodb php8.3-imagick

PHP 버전 확인

php -v
PHP 8.3.21 (cli) (built: May  9 2025 06:27:43) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.21, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.21, Copyright (c), by Zend Technologies

PHP-FPM 서비스 시작 및 활성화

sudo systemctl enable --now php8.3-fpm

Nginx와 PHP-FPM 연동

Nginx 설정 파일 수정

vim /etc/nginx/conf.d/default.conf
더보기

---

server {
    listen       80;
    server_name  localhost;

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

    access_log  /var/log/nginx/host.access.log  main;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    # 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/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           html;
        #fastcgi_pass   127.0.0.1:9000;
        fastcgi_pass   unix:/run/php/php8.3-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

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

---

설정 파일 문법 확인

sudo nginx -t

Nginx 재시작

sudo systemctl restart nginx

PHP 테스트

echo "<?php phpinfo();" | sudo tee /usr/share/nginx/html/info.php

권한 및 보안 설정

웹 디렉토리 권한 설정

sudo chown -R www-data:www-data /usr/share/nginx/html
sudo chmod -R 755 /usr/share/nginx/html

PHP-FPM 소켓 파일 확인

ls -l /run/php/php8.3-fpm.sock

Nginx 및 PHP-FPM 로그 확인

sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/php8.3-fpm.log

 

우분투 24.04에 Nginx 1.28과 PHP 8.3이 성공적으로 설치되고 연동됩니다.

 

반응형